Add a new row in specific place in a dataframe

前端 未结 4 796
野的像风
野的像风 2020-12-29 11:18

Heres my data:

 > data
  Manufacturers       Models
1   Audi                RS5  
2   BMW                 M3  
3   Cadillac            CTS-V  
4   Lexus           


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 11:34

    this function would improve and solve your problem:

    INSERT_NA_ROW <- function(indice, tabla) {
      new_Row <- NA
      long <- NROW(tabla)
      new_Data<- rbind(tabla[1:indice,], new_Row ,tabla[(indice + 1):(long),])
      return(new_Data)
    } # Insert Row in index of dataframe
    

    Thanks for read me!

提交回复
热议问题