I want to read a multiple sheets into R and I was able read them using the following code:
library(gdata)
dataFile <- file.path('.../Desktop/readMultiSheetExample.xls')
dat<-NULL; for (i in 1:2) { dat[[i]]<-read.xls(dataFile,sheet=i,head=T) }
Sheet 1
obs cens
2.9 D
1.7 D
1.2 U
7.4 D
1.2 U
Sheet 2
obs cens
2.4 D
0.5 D
1.4 U
1.5 U
0.4 U
1.1 U
1.1 U
I wrote a simple function to give simple stats. How can write a code that would allow me to access individual sheet and calculate summaryStats for each individual sheet and then combine the result for each sheet into a nice table.
For each sheet, I would like
# modify second column
data$cens <- ifelse(data$cens == “U”, 1,0)
summaryStats <- function (data)
{
obs <- data$obs
cens <- data$cens
n <- length(obs)
nCens <- length(cens)
maxValue <- max(obs)
minValue <-min(obs)
result <- data.frame(n,nCens,minValue,maxValue )
names(result) <- c('N','N.Censored',"Min",'Max')
return(result)
You could use
lapplyto run a function on each list element andrbindto combine the results.