let’s say I have this df
original_df <- data.frame(
ID = c(1, 2, 3),
Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 22)
)
I wish the following output
ID Name Age
1 1 Alice 25
2 2 Bob 30
3 2 Bob 30
4 3 Charlie 22
>Solution :
You can repeat your row number in [:
original_df[c(1, 2, 2, 3), ]
To make it more flexible, you can use append to create a new sequence of row indices.
new_seq <- append(seq(nrow(original_df)), values = 2, after = 2)
original_df[new_seq, ]