Question: I have a dataframe like this:

```
a=c(rep(1,3), rep(2,2))
b=c(2,4,7,9,1)

df <- data.frame(a,b)

> df
  a b
1 1 2
2 1 4
3 1 7
4 2 9
5 2 1

```

I want to create a list with as many elements as different values in column "a" (in this case "2") and store the values of column "b" in the list according to column "a". I am trying something like this:

```
lst <-list()
ff <-function(){lili[[df$a]] <- df$b}
apply(ff, df)

```

Which obviously is not working...But what I basically want to do is:

```
lst <- list(c(2,4), c(7,9,1))

```

but using apply over the rows of a large df to populate the list.

Answer: 
```
split(df$b, df$a)
$`1`
[1] 2 4 7

$`2`
[1] 9 1

```

This is extra nice because the list names will be the values of `a` by default.

That said, I agree with alistaire's comment. This seems like an XY problem - there's a good chance that whatever you do next would be done easily by `data.table` or `dplyr` without creating this separate list.
Try this: `lapply(unique(df$a),function(x) df$b[df$a==x])`