I have a problem with restructuring data. For the entire data set, I need to duplicate each row and insert it to the row right after it, such that
row 1
duplicate of row 1
row 2
duplicate of row 2
and so on and so forth for the entire data set.
I have a problem with restructuring data. For the entire data set, I need to duplicate each row and insert it to the row right after it, such that
row 1
duplicate of row 1
row 2
duplicate of row 2
and so on and so forth for the entire data set.
You could try rep
df1[rep(1:nrow(df1),each=2),,drop=FALSE]
Or using splitstackshape
library(splitstackshape)
expandRows(df1, 2, count.is.col = FALSE)
df1 <- data.frame(Col1=1:5, Col2=6:10)