[R] add repeated rows in data frame (without a loop)

Nicolas Gutierrez nicolasg at uw.edu
Tue Feb 22 23:48:36 CET 2011


Hi All,

I have a data frame "pop":

 >    id  xloc  yloc  size
 > 1  1	  10	12    95
 > 2  2    11	10    81

And I want to add the vector "rec" to the data frame "n" times (without 
using a loop):

 > rec=c(3, 5, 5, 10)
 > n=2

The result I want:

 >    id  xloc  yloc size
 > 1  1	  10	12   95
 > 2  2    11	10   81
 > 3  3	  5	5    10
 > 4  3    5     5    10		

I know I can use pop=rbind(pop, rec) to add the vector "rec" once. What 
about adding the same vector "n" times without a for loop?  Any hints?

THANKS!

Nico



More information about the R-help mailing list