Looping through Columns replicating each column fetched six times
问题 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. 回答1: 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