I have a data frame that looks like this:
a<-c('a', 'b', 'c', 'd', 'e')
b<-c(1, 2, 3, 2, 3)
df<-data.frame(a, b)
a b
1 a 1
2 b 2
3 c 3
4 d 2
5 e 3
I would like to duplicate the values in column a by the number in column b, so as to get a vector/data.frame that looks like this:
c<-c('a', 'b', 'b', 'c', 'c', 'c', 'd', 'd', 'e', 'e', 'e')
c
1 a
2 b
3 b
4 c
5 c
6 c
7 d
8 d
9 e
10 e
11 e
Thanks for your suggestions.
Look at
?rep, as in:The factor bit is annoying as it is how R created
bindf. Either dothen the above answer, or just coerce the result to a character vector: