[R] Adding a row at top of dataframe

Nikhil Kaza nikhil.list at gmail.com
Mon May 17 19:14:48 CEST 2010

Does this work?

cars2 <- cars
cars2[2:nrow(cars)+1,] <- cars2[1:nrow(cars),]
cars2[1,] <- NA

Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

nikhil.list at gmail.com

On May 17, 2010, at 11:28 AM, ecvetano at uwaterloo.ca wrote:

> I have a large data frame 48:2185 with different numbers.
> I would like to add only one row at the very top of my data frame  
> with 0's or NA's.
> I don't know which approach to use. Should i create 2 different data  
> frames and merge them? Ive also tried the rbind command with no  
> luck. I would appreciate some help to achieve what I'm trying to  
> create.
> Thanks!
> ______________________________________________
> R-help at 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.

More information about the R-help mailing list