Yoke Keong

Reading excel files with readxl R package

Recently, Hadley Wickham introduced a new package to read Excel files (XLS, XLSX). The main advantage is that no external dependencies is required for readxl. (xlsx package requires Java Runtime to be installed)

With xlsx:

1library(xlsx)
2library(httr)
3url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx"
4GET(url, write_disk("iris.xlsx", overwrite=TRUE))
5iris <- read.xlsx("iris.xlsx", sheetIndex=1, header=TRUE)
6head(iris, 3)
1##   NA. Sepal.Length Sepal.Width Petal.Length Petal.Width Species
2## 1   1          5.1         3.5          1.4         0.2  setosa
3## 2   2          4.9         3.0          1.4         0.2  setosa
4## 3   3          4.7         3.2          1.3         0.2  setosa

With readxl:

1library(readxl)
2library(httr)
3url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx"
4GET(url, write_disk("iris.xlsx", overwrite=TRUE))
5iris <- read_excel("iris.xlsx")
6head(iris, 3)
1##     Sepal.Length Sepal.Width Petal.Length Petal.Width Species
2## 1 1          5.1         3.5          1.4         0.2  setosa
3## 2 2          4.9         3.0          1.4         0.2  setosa
4## 3 3          4.7         3.2          1.3         0.2  setosa

Find out more on the features, usage and installation at its Github repository.

<< Previous Post

|

Next Post >>

#R #Readxl