I want to create a named list where each name has multiple values. I can only find how to do this if for each name there is one value. My solution that I am using now is
df <- data.frame(col1=c('a','a','b','b'), col2=c(1,2,3,4))
l <- list()
for(letter in unique(df$col1)){
l[[letter]] <- df[df$col1==letter,]$col2
}
> l
$a
[1] 1 2
$b
[1] 3 4
but what is a better way to do this?