How to disaggregate a data frame consisting of list of lists

Viewed 1328

If I construct a data frame as

# constructing df
a <- c(rep("A", 3), rep("B", 3), rep("A",2))
b <- c(1,1,2,4,1,1,2,2)
#c <- c("ir", "ir", "br", "ir", "us", "us", "ir", "br")
c <- c(1, 2, 3, 4, 4, 4, 4, 5)
df <- data.frame(a,b,c)

I can aggregate that via:

df_red <- aggregate(list(track = c), df[,c("a", "b")], '[')

What is the best way to disaggregate that back to what it was before?

IN another words, how can I convert this:

  a b   track
1 A 1    1, 2
2 B 1    4, 4
3 A 2 3, 4, 5
4 B 4       4

to this:

  a b c
1 A 1 1
2 A 1 2
3 A 2 3
4 B 4 4
5 B 1 4
6 B 1 4
7 A 2 4
8 A 2 5
1 Answers
Related