Lab squeeze - FUNctions
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):
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)