Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home / Members / Daniel Ricard / March 19th 2007 lab squeeze - FUNctions / Lab squeeze - FUNctions
Navigation
Log in


Forgot your password?
 

Lab squeeze - FUNctions

I can't be at the lab meeting, here is my little contribution.

Hi guys, sorry I can't be at the meeting.

I want to demonstrate the use of a very useful package for R called xlsReadWrite which allows one to read/write directly from/to Excel from R.

Say someone gives you an Excel file called "somedata.xls". The first worksheet contains information about tows, the second worksheet has catch data and the third worksheet has species names.

You can easily load all this into R using the following (assuming that you have installed the xlsReadWrite package):

library(xlsReadWrite)
info <- read.xls("somedata.xls", sheet=1)
catch <- read.xls("somedata.xls", sheet=2)
species <- read.xls("somedata.xls", sheet=3)

The three data frames now contain all the data from the Excel spreadsheet. There are a few more options for that function, see the help page (?read.xls).

Similarly, you can write to the Excel file using the "write.xls" function provided by the package. Say you want to store data into an Excel file, this will do the trick:

mydata <- data.frame(col1=seq(1:200), col2=rpois(200, 100), col3=rep("A", 200))
write.xls(mydata, "mydata.xls", sheet=1)

Cheers,

Dan

Document Actions

« March 2017 »
March
MoTuWeThFrSaSu
12345
6789101112
13141516171819
20212223242526
2728293031