[R] repeat a sequence - but not for a full number of times

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Thu Jul 21 00:15:46 CEST 2011


Apologies, for a very simple question. I forgot how to do it -
although I remember reading about getting a warning in such a
situation.

I have a data frame. It happens to be 10 rows but it could be 11 or 3 or 13...
x<-data.frame(a=1:10)
I need to add variable "b" that is a sequence of 1:3 - repeated again
and again so that the result is:
x
a b
1 1
2 2
3 3
4 1
5 2
6 3
7 1
8 2
9 3
10 1


Thanks a lot!
-- 
Dimitri Liakhovitski
marketfusionanalytics.com



More information about the R-help mailing list