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

David Kreil kreil at ebi.ac.uk
Tue Dec 9 06:02:36 CET 2003


Hi,

I have a data.frame that I need to construct iteratively.

At the moment, I'm doing:

d<-data.frame(x=c(),y=c(),z=());

# {and, within some loop}

  d<-rbind(d,data.frame(x=newx,y=newy,z=newz);


While this works, it is horribly verbose and probably not efficient, either. 
My real data.frame has, of course, many more columns, which can be of 
different modes.

I vaguely recall that in much earlier R versions the following worked

  d[dim(d)[1]+1,]<-c(newx,newy,newz);

but not anymore (both 1.7 and 1.8 give "subscript out of bounds").

Can anyone suggest a more elegant and/or efficient way of achieving this, 
please? Cc to this address highly appreciated.

With many thanks,

David.


------------------------------------------------------------------------
Dr David Philip Kreil                 ("`-''-/").___..--''"`-._
Research Fellow                        `6_ 6  )   `-.  (     ).`-.__.`)
University of Cambridge                (_Y_.)'  ._   )  `._ `. ``-..-'
++44 1223 764107, fax 333992         _..`--'_..-_/  /--'_.' ,'
www.inference.phy.cam.ac.uk/dpk20   (il),-''  (li),'  ((!.-'




More information about the R-help mailing list