I have a list contains list as elements. I want to convert all elements into data frame. Instead of using for loop. I used lapply function as follow:
myDF=lapply(mylist,FUN=as.data.frame)
However it's not converting.
class(myDF[1])
still returns list.
Any ideas? Thank you so much for your help,
To look at the first element of the list as-is (ie not as a list) you will want to use [[
instead of [
. So
class(myDF[[1]])
will tell you the class of the first list element in myDF
.
Another way to see this is to look at the difference between myDF[1]
and myDF[[1]]
. myDF[1]
returns the first element of the list as a single-element list , whereas myDF[[1]]
returns the first element of the list as itself. See help(Extract)
for more.
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.