Hello!
I have a list consisting of several data frames, but now I only need one column of each. What I need to do now is to extract one column (the same column every time) of each data frame and save them all in a new matrix. The problem sounds like a rather basic one, but I couldn't find the right syntax for this operation. So thanks for any help.
Best regards
What shape/dimensions of matrix is desired?
The column should be row-binded. With Matrix dimensions being n x k, n should be length of the column and k should be numbers of data frames (and therefore length of the list, I guess). I am trying an approach with a separate function now:
extractwisp <- function(x){
x <- x[,4]
}
wisp <- as.matrix(lapply(ok_list, extractwisp))
I'm checking now if that works.
It seems to work so far, but the output is still a list. Where is the problem? Is it possible to convert it to a real matrix easily?
sapply(ok_list, extractwisp)
i.e. if n and k represent rows and columns, respectively.
Ah, sapply is, what I was looking for. Seems to work, thank you!