Hi. May be this: df = data.frame( A=c('a','b','c'), B=c(1,2,3), C=c(10,20,30), stringsAsFactors=FALSE)
newrow = c('X', 100, 200) rbind(df,newrow)[c(1,4,2,3),] Andrija On Thu, Nov 24, 2011 at. 6:05 PM, Sammy Zee <szee2...@gmail.com> wrote: > Is there easy way (without copying the existing rows to a temporary > location and copying back) to add a new row to a specific index location in > an existing data frame? > > Example > > df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) > > newrow = c('X', 100, 200) > > I want to add the newrow as the second row to the data frame df > > Please suggest a solution that is efficient for a data frame that can have > millions of rows, and I want to add a new row in any given index location > of the data frame. > > Thanks, > Sammy > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.