I am cleaning several excel files in R. They unfortunately are of unequal dimensions, rows and columns. Currently I am storing each excel sheet as a data frame in a list. I
There is no need for a wrapper function, just use lapply and pass it a blank argument at the end (to represent the columns)
lapply(df.list, `[`, 4, )
This also works with any type of row argument that you would normally use in myDF[ . , ] eg: lapply(df.list,[, c(2, 4:6), )
.
I would suggest that if you are going to use a wrapper function, have it work more like [ does: eg
Grab(df.list, 2:3, 1:5) would select the second & third row and first through 5th column of every data.frame and
Grab (df.list, 2:3) would select the second & third row of all columns
Grab <- function(ll, rows, cols) {
if (missing(cols))
lapply(ll, `[`, rows, )
else
lapply(ll, `[`, rows, cols)
}
Grab (df.list, 2:3)