I would like to use tapply on a list of data frames in oder to calculate sums for individual groups and then tabulate the occurence of the value 0. On an individual data frame I would do this:
sums <- tapply(my_data_frame$V3, my_data_frame$V2, sum)
table(unlist(sums==0))
Since I have to calculate this for a number of files, I have loaded them all into a list:
files <- Sys.glob("*txt")
listOfFiles <- lapply(files, function(x) read.table(x, skip = 1, sep = "\t"))
listOfFiles <- lapply(listOfFiles, function (x) na.omit(x))
I have tried this, but it does not work:
lapply(listOfFiles, tapply(
lapply(listOfFiles, "[", c(2)),
lapply(listOfFiles, "[", c(3)),
sum)
)
Could someone give me any hints on what to do?