简体   繁体   中英

Turning into data.frame into a list based on ids

I have a 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:

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)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM