Rep and Seq

ondansetron

TS Contributor
#1
Was tinkering with rep and seq today and wondering about the following:

> rep(c(5,12,13), each=2)
[1] 5 5 12 12 13 13

I wondered what would happen if I specified seq(1:3) for each=...
I assumed this would happen:

5, 12, 12, 13, 13, 13

but instead got:

> rep(c(5,12,13), each=c(seq(1:3, by=1)))
Error in seq.default(1:3, by = 1) : 'from' must be of length 1

Any idea why R won't recognize this and allow the "each"= argument to differ for difference elements? I would imagine this has some kind of utility to repeat elements a differing number of times. What would be a good solution for the problem above?
 

Dason

Ambassador to the humans
#2
It's all in the help file. The each parameter will only take a single number. You probably the want the times parameter