This is a very simple question, but it annoys me, so I ask.
I need a sequence of repeating numbers, i.e. 1 1 ... 1 2 2 ... 2 3 3 ... 3 etc. The way I did this was
nyear<-20 names<-c(rep(1,nyear),rep(2,nyear),rep(3,nyear),rep(4,nyear), rep(5,nyear),rep(6,nyear),rep(7,nyear),rep(8,nyear))
which works, but is clumsy, and obviously does not scale well. How do I repeat N integers M times each in a sequence? I tried nesting seq () and rep (), but this is not quite the way I wanted. I can obviously write a for loop that will do this, but it also seems awkward - there must be an internal way to do this!
r seq
Wesley Burr Jun 21 '11 at 21:15 2011-06-21 21:15
source share