Heres my data:
> data
Manufacturers Models
1 Audi RS5
2 BMW M3
3 Cadillac CTS-V
4 Lexus ISF
I would like to add 1 row in the fourth row, like this:
> data
Manufacturers Models
1 Audi RS5
2 BMW M3
3 Cadillac CTS-V
4 Benz C63
5 Lexus ISF
I have tried to use the rbind() like this:
Benz = data.frame(Manufacturers = "Benz", Models = "C63")
newdata = rbind(data,Benz)
But I cannot add to the place I want. I would appreciate any help on this question. Thanks a lot.
In case you don't want the index but rather a one-off "quick fix" for some spreadsheet-like appearance, you might resort to
newData <- rbind( data[1:3,], Benz, data[ 4,] )
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With