1

I have this data frame where the column names are from v1 to v292. There are 17 observations. I need to iterate over the columns and replicate each column fetched 6 times.

For example:

v1 v2 v3 v4
1  3  4  6
3  4  3  1

What the output should be

x
1
3
1
3
1
3
1
3
1
3
1
3
3
4
3
4
3
4
3
4
3
4
3
4 .. and so on.

Please help. Thank you in advance.

Ami
  • 197
  • 1
  • 12

1 Answers1

2

You could use rep

data.frame(x = unlist(rep(df, each = 6)))

Checking output with each = 2

data.frame(x = unlist(rep(df, each = 2)))

#   x 
#1  1
#2  3
#3  1
#4  3
#5  3
#6  4
#7  3
#8  4
#9  4
#10 3
#11 4
#12 3
#13 6
#14 1
#15 6
#16 1
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thanks Ronak. It helped a lot. Moreover slight tweaking the code served another output as well. – Ami Dec 06 '18 at 11:49