readxl – a new r package to import data from excel

There are many ways to import data from excel spreadsheets into R (see ‘R Tutorial on Reading and Importing Excel Files into R’).

With Hadley Wickham’s recent r-package readxl, it is possible to import large excel files very quickly.

library(readxl)
# example 1
mydata <- read_excel("excelfile.xls", sheet = "sheet1")

# example 2
mydata <- read_excel("C:/myfiles/excelfile.xlsx", sheet = 1)

# example 3
mydata <- read_excel("excelfile.xlsx", sheet = 1, na = "99")

Example 1 loads the sheet sheet1 from excel file named excelfile.xls
The code examples are quite straightforward and easy to understand. The sheet we wish to import maybe specified either as string (the name of a sheet, see example 1) or as integer (the position of the sheet, see example 2).

In case the excel file we wish to import is not located in the current working directory, we need to specify the path to the excel file (see example 2).

Moreover, it is possible to specify a missing value (only one). In example 3, the value 99 will be treated as missing value.

Since the readxl package has been published only very recently, it is rather likely that the author will add some more features in the future.

Advertisements

About norbert

I am post doc at the Department of Medical Psychology and Sociology, Leipzig University (GER), with degrees in sociology (MA) and public health (MPH).
This entry was posted in Data Management and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s