Coerce dataframe groups to list

Viewed 55

I have a dataframe such as

id <- c(1,1,1,2,2,3,3,3,3)
element <- c(25122,356,4454,5432,342340,12443,12354,123536,234134)
df <- data.frame(id = as.factor(id), element)

I would like to create a list of the id groups with their corresponding elements such as:

dflist <- list(c(25122,356,4454), c(5432,342340), c(12443,12354,123536,234134))
2 Answers
Related