How to load data from excel into R

Like many other researchers I use excel for organizing the data, and R for analysis. Here’s a short, but useful code snippet:

# Install package
install.packages("XLConnect")
# Load package
library(XLConnect)
# Or specify directory of package
library("XLConnect", lib.loc="C:/Users/YOURNAME/Documents/R/win-library/3.0")
# Load your spreadsheet (with default header = TRUE)
df <- readWorksheet(loadWorkbook('C:/Users/YOURNAME/Documents/SpreadsheetName.xlsx'),sheet=1)
# Or specify what to load
df <- readWorksheet(SpredsheetName, sheet = "mtcars",
	startRow = 3, startCol = 3, endRow = 15, endCol = 18)

				
Advertisements

About TeeYay

Ph.D. in Assessment, Monitoring, and Geospatial Analysis (applied statistics) from the University of Minnesota, USA.
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

One Response to How to load data from excel into R

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