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.

# 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.

Author: norbert

Biometrician at Clinical Trial Centre, Leipzig University (GER), with degrees in sociology (MA) and public health (MPH).

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: