R: Insert a vector as a row in data.frame

Viewed 62637

Can I insert a vector as a row in a data.frame? If so how?

3 Answers

rbind is good, but really tricky though as to handle the exact row number before and after. A more rapid way is to use insertRow in the package miscTools.

In the dataset example above, the code would be :

my.df <- as.matrix(data.frame(a = runif(10), b = runif(10), c = runif(10)))
my.vec <- c(1, 1, 1)
new.df <- insertRow(my.df,7,my.vec)
new.df

Hope would be helpful.

Related