본문 바로가기

Data Mining & R

R Excel read

XLConnect also can write Excel files, including changing cell formatting, in both Excel 97–2003 and Excel 2007/10 formats.

To find out more about XLConnect, you can read the excellent package vignette.

By now you’re probably itching to get started with an example. Assume you want to read an Excel spreadsheet in your user directory called Elements.xlsx. First, install and load the package; then create an object with the filename:

> install.packages("XLConnect")
> library("XLConnect")
> excel.file <- file.path("~/Elements.xlsx")

Now you’re ready to read a sheet of this workbook with the readWorksheetFromFile() function. You need to pass it at least two arguments:

  • file: A character string with a path to a valid .xls or .xlsx file

  • sheet: Either an integer indicating the position of the worksheet (for example, sheet=1) or the name of the worksheet (for example, sheet=”Sheet2″)

The following two lines do exactly the same thing — they both import the data in the first worksheet (called Sheet1):

> elements <- readWorksheetFromFile(excel.file, sheet=1)
> elements <- readWorksheetFromFile(excel.file, sheet="Sheet1")


설치시 문제 ---------------------------




This error is often resolved by installing a Java version (i.e. 64-bit Java or 32-bit Java) that fits to the type of R version that you are using (i.e. 64-bit R or 32-bit R). This problem can easily effect Windows 7 users, since they might have installed a version of Java that is different than the version of R they are using.

Note that it is necessary to ‘manually download and install’ the 64 bit version of JAVA. By default, the download page gives a 32 bit version .

You can pick the exact version of Java you wish to install from this link. If you might (for some reason) work on both versions of R, you can install both version of Java (Installing the “Java Runtime Environment” is probably good enough for your needs).
(Source: Uwe Ligges)

Other possible solutions is trying to re-install rJava.

If that doesn’t work, you could also manually set the directory of your Java location by setting it before loading the library:

Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre7') # for 64-bit version
Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre7') # for 32-bit version
library(rJava)


'Data Mining & R' 카테고리의 다른 글

R TUTORIAL  (0) 2017.01.06
R Excel Data 사용  (0) 2017.01.06
R GPU 사용 예제(package gputools)  (0) 2017.01.04
R 병렬처리(doParallel , Foreach) 예제  (0) 2017.01.04
R을 사용한 다중회귀분석 (Multiple regression in R)  (0) 2017.01.04