My understanding of the question is that you need a function that returns the second column data.frame from the list data, with the optional worst argument, which allows you to limit it to the last observation.
I think the easiest way to do this is to write a helper function and then apply it to your list with lapply .
I wrote a selector function that takes a row and column argument, as well as the worst argument. I think this does everything you need.
df1 <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10)) df2 <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10)) ldf <- list(df1, df2) selector <- function(DF, col, row=NULL, worst=FALSE){ if(!is.null(row)) return(DF[row, col]) if(!missing("col")) if(col > ncol(DF)) return(NA) if(!is.null(row)) if(row > nrow(DF)) return(NA) if(worst) { tail(DF[,col, drop=F],1) } else { DF[row, col, drop=FALSE] } } lapply(ldf, selector, worst=T)
ricardo
source share