I created a list of dataframes called "list" and want to select only certain columns of every dataset in the list.
library(dplyr)
new_list <- lapply(list, select(list, Date))
It returns an error because class(list[1]) is not dataframe but still a list. class(list[[1]]) is dataframe. I don't understand that because the elements in my list should be dataframes and I also don't know how I can use "lapply" anyway.
Thanks for your help!
I think your syntax is just a little off. Try using an anonymous function instead:
l <- list(mtcars,mtcars)
lapply(l,function(x) select(x,cyl,mpg))
另外要记住[
本身是一个函数,因此:
new_list <- lapply(list, '[', c("list", "Date"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.