[R] append data

Pierre Kleiber pkleiber at honlab.nmfs.hawaii.edu
Fri Jan 26 21:02:02 CET 2001


Yu-Ling Wu wrote:
> 
> Hi,
> 
> I read a dataset into R. It looks like this:
> 
> > rawlist
> x1      x2       x3
> 2        12        64
> 5        12        42
> 5         9        42
> 18        14       535
> 26        23       751
> 
> Now I want to append some values of zero to let it
> look like this:
> 
> x1      x2       x3
> 2        12        64
> 5        12        42
> 5         9        42
> 18        14       535
> 26        23       751
> 0          0         0
> 0          0         0
> 0          0         0
> 0          0         0
> 
> How to do this?

One possibility (assuming that rawlist is a data frame) is:

  rawlist <- sapply(rawlist,function(x)c(x,rep(0,4)))


-- 
-----------------------------------------------------------------
Pierre Kleiber             Email: pkleiber at honlab.nmfs.hawaii.edu
Fishery Biologist                     Tel: 808 983-5399/737-7544
NOAA FISHERIES - Honolulu Laboratory         Fax: 808 983-2902
2570 Dole St., Honolulu, HI 96822-2396 
-----------------------------------------------------------------
 "God could have told Moses about galaxies and mitochondria and
  all.  But behold... It was good enough for government work."
-----------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list