[英]R lapply into data frame
I have a list contains list as elements. 我有一个包含列表作为元素的列表。 I want to convert all elements into data frame.
我想将所有元素转换为数据框。 Instead of using for loop.
而不是使用for循环。 I used lapply function as follow:
我使用了lapply函数,如下所示:
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
. 会告诉您
myDF
第一个列表元素的类。
Another way to see this is to look at the difference between myDF[1]
and myDF[[1]]
. 另一种查看方式是查看
myDF[1]
和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. myDF[1]
返回列表的第一个元素作为单元素列表 ,而myDF[[1]]
返回列表的第一个元素本身。 See help(Extract)
for more. 有关更多信息,请参见
help(Extract)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.