Hi all, I have the data set df with three varaibles, x1 x2 x3 1 2 5 2 4 1 5 6 0 1 1 2 I want to insert more rows ( eg, 3 rows with value filled with zeros) 1 2 5 2 4 1 5 6 6 1 1 2 0 0 0 0 0 0 0 0 0 Can any body help me out? Thanks
Try this: rbind(df, matrix(0, 3, 3, dimnames = list(NULL, names(df)))) On Fri, Oct 23, 2009 at 11:44 AM, Ashta <sewashm at gmail.com> wrote:> Hi all, > > I have the data set ?df with three varaibles, > > x1 x2 x3 > 1 ?2 ? 5 > 2 ?4 ? 1 > 5 ?6 ? 0 > 1 ?1 ? 2 > > I want to insert more rows ( eg, 3 rows with value ?filled with zeros) > 1 ?2 ? 5 > 2 ?4 ? 1 > 5 ?6 ? 6 > 1 ?1 ? 2 > 0 ?0 ?0 > 0 ?0 ?0 > 0 ?0 ?0 > > Can any body help me out? > > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
?rbind
df1 <- data.frame(matrix(rep(0,9),nrow=3))
names(df1) <- c("x1","x2","x3")
rbind(df,df1)
--- On Fri, 10/23/09, Ashta <sewashm at gmail.com> wrote:
> From: Ashta <sewashm at gmail.com>
> Subject: [R] Inserting rows
> To: "R help" <r-help at r-project.org>
> Received: Friday, October 23, 2009, 9:44 AM
> Hi all,
>
> I have the data set? df with three varaibles,
>
> x1 x2 x3
> 1? 2???5
> 2? 4???1
> 5? 6???0
> 1? 1???2
>
> I want to insert more rows ( eg, 3 rows with value?
> filled with zeros)
> 1? 2???5
> 2? 4???1
> 5? 6???6
> 1? 1???2
> 0? 0? 0
> 0? 0? 0
> 0? 0? 0
>
> Can any body help me out?
>
> 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.
>
__________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!
http://www.flickr.com/gift/