[R] How to append to a data.frame?

Jason Turner jasont at indigoindustrial.co.nz
Tue Dec 9 11:50:29 CET 2003


David Kreil wrote:

> Ok, how can I both allocate storage and specify column names in a data.frame 
> call, please? Apologies if I'm being slow here.
> 
> With many thanks again,
> 
> David.
> 

Something like.... (UNTESTED code follows)

templateColumn <- rep(NA,1000) # for 1000 rows

foo <- data.frame( x = templateColumn,
   y = templateColumn,
   z = templateColumn )  # or however many columns you need

bar <- foo

for(ii in your.iterative.sequence) {
   if(ii > 1000) {
     bar <- rbind(bar,foo)
   }
   bar[ii,] <- your.function()
}

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list