Hi Nithin,
rep() is used to replicate a vector, so you can use it for your problem.
Syntax: rep(vector,replication_number).
Ex: rep(c(1:5),5)
To add the replicated vector to a data frame, you can give replication_number as [number of rows]/[size of vector]
For suppose if the data frame consists of 23 rows and vector has 5 elements, then use code as
length.out is used to mention the size of the new vector after replication. It ignores is the size of replicated is more than data frame size.
> z = data.frame(x=1:23,y=21:43)
> z
x y
1 1 21
2 2 22
3 3 23
4 4 24
5 5 25
6 6 26
7 7 27
8 8 28
9 9 29
10 10 30
11 11 31
12 12 32
13 13 33
14 14 34
15 15 35
16 16 36
17 17 37
18 18 38
19 19 39
20 20 40
21 21 41
22 22 42
23 23 43
> z$vec = rep(c(1:5),5,length.out = nrow(z))
> z
x y vec
1 1 21 1
2 2 22 2
3 3 23 3
4 4 24 4
5 5 25 5
6 6 26 1
7 7 27 2
8 8 28 3
9 9 29 4
10 10 30 5
11 11 31 1
12 12 32 2
13 13 33 3
14 14 34 4
15 15 35 5
16 16 36 1
17 17 37 2
18 18 38 3
19 19 39 4
20 20 40 5
21 21 41 1
22 22 42 2
23 23 43 3