How to insert rows at a specific place in a data frame?

That works they way I think the OP needs it to work (NA, rather than ""), but to give actual blanks (and avoid the row numbering glitch)

> blank <- c("","","","")
> top <- head(df,4)
> bottom <- tail(df,2)
> df.new <- rbind(top,blank,blank,blank,blank,bottom)
> rownames(df.new) <- seq(1,nrow(df.new),1)
> df.new
   A B C D
1  2 4 1 3
2  1 5 0 2
3  2 3 2 1
4  0 0 0 0
5         
6         
7         
8         
9  0 1 7 0
10 1 3 4 0

(Would've posted a reproducible example, called a reprex for for some reason it objected to the code.)

1 Like