[R] merge

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Apr 19 12:29:05 CEST 2002


On Fri, 19 Apr 2002, juli g. pausas wrote:

> Dear R-users,
> I'm trying to merge 2 data.frames that have different number of rows,
> with a common column. Is this possible? Here a simple exemple, with the

Yes, see the example on the help page.

> error that I get:
>
> a <- 1:20
> b <- 21:40
> ab <- data.frame(a, b)
> a <- 1:40
> c <- 41:80
> ac <- data.frame(a, c)
> rm(a, b, c)
> zz <- merge(ab, ac, by.x=ab$a, by.y=ac$a)
>
> Error in fix.by(by.x, x) : `by' must match numbers of columns

I think you intended

     merge(ab, ac, by="a")

You can read up on how to specify the `by' columns in the Details section,
or just follow the example.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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