0

I have a data frame looks like below (but much longer):

Column_A  Column_B  Column_C
Bob       Henry     3
Bill      Alice     2
...

I want to expand this data frame based on column c:

Column_A  Column_B  Column_C
Bob       Henry     1
Bob       Henry     1
Bob       Henry     1
Bill      Alice     1
Bill      Alice     1
...

Basically, the numbers in the column c of the original data frame determines the number of duplicated rows (For example, in the original data frame, the first row has value of 3 in column C and thus in the new data frame, there are will be three rows with "Bob" in column A and "Henry" in column B).

RandomThinker
  • 391
  • 1
  • 6

1 Answers1

1
result = your_data[rep(1:nrow(your_data), times = your_data$Column_C), ]
result$Column_C = 1
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294