[英]Turning into data.frame into a list based on ids
I have a data.frame: 我有一个data.frame:
DF <- data.frame(id=c(1,1,2,2), event=c("merged", "discussed", "merged", "discussed"))
Now I want to turn it into a list, in such a way that the list contains two entries - one for each id (ie 1 and 2), and then only the records that correspond to those entries, as such: 现在,我想将其变成一个列表,以使该列表包含两个条目-每个ID(即1和2)一个,然后仅包含与这些条目相对应的记录,例如:
List of 2:
[1] name: "1", data.frame
id event
1 1 merged
2 1 discussed
[2] name: "2", data.frame
id event
1 2 merged
2 2 discussed
Obviously I am looking for a generalizable solution that will scale up beyond this minimal example. 显然,我正在寻找一种可扩展的解决方案,该解决方案将超出此最小示例的范围。
尝试split
split(DF, DF$id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.