Repeat elements of vector in R

Posted by bshor on Stack Overflow See other posts from Stack Overflow or by bshor
Published on 2010-05-12T19:07:00Z Indexed on 2010/05/12 22:24 UTC
Read the original article Hit count: 164

Filed under:
|

Hi,

I'm trying to repeat the elements of vector a, b number of times. That is, a="abc" should be "aabbcc" if y = 2.

Why doesn't either of the following code examples work?

sapply(a, function (x) rep(x,b))

and from the plyr package,

aaply(a, function (x) rep(x,b))

I know I'm missing something very obvious ...

© Stack Overflow or respective owner

Related posts about r

    Related posts about plyr