[R] appending similar data frames?

Thomas Lumley tlumley at u.washington.edu
Mon Dec 3 20:41:31 CET 2001


On 3 Dec 2001, Michael A. Miller wrote:

> Dear R gang,
>
> Can anyone help me sort out how to append one data frame to
> another while adding a factor to distinguish which was the
> original frame?
>
> For example, I have two frames, x and y
>
> > x
>   exp size
> 1   a   10
> 2   b    9
> 3   c   10
> 4   d   12
> 5   e   11
>
> > y
>   exp size
> 1   a   13
> 2   b   15
> 3   c   12
> 4   d   20
> 5   e   15
>
> and I'd like to create a new frame that looks like
>
>    exp size set
> 1    a   10   x
> 2    b    9   x
> 3    c   10   x
> 4    d   12   x
> 5    e   11   x
> 6    a   13   y
> 7    b   15   y
> 8    c   12   y
> 9    d   20   y
> 10   e   15   y
>

rbind(cbind(x,set=rep("x",NROW(x))),
      cbind(y,set=rep("y",NROW(x)))
      )

will do it.

	-thomas


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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