[R] Problems with merge

Prof Brian D Ripley ripley at stats.ox.ac.uk
Sat Mar 16 09:17:40 CET 2002


On Sat, 16 Mar 2002, Prof Brian D Ripley wrote:

> > > # Here is another different problem with merge
> > > # we specified no sorting but the rows are not in the same order as e.df
>
> Do read the help page. This is sorted in the order specifed there:
>
>      The rows are by default lexicographically sorted on
>      the common columns, but are otherwise in the order in which they
>      occurred in `x'.
>
> > > e.df <- data.frame(x=c(1,4,5,1,3,5),y=c("A","D","E","A","C","E"),z=c(6,9,10,6,8,10))
> > > e.df
> >   x y  z
> > 1 1 A  6
> > 2 4 D  9
> > 3 5 E 10
> > 4 1 A  6
> > 5 3 C  8
> > 6 5 E 10
> > > merge(e.df,unique(e.df),sort=F)
> >   x y  z
> > 1 1 A  6
> > 2 1 A  6
> > 3 4 D  9
> > 4 5 E 10
> > 5 5 E 10
> > 6 3 C  8

Sorry, I have problems parsing expressions with no spaces in!
merge(x = e.df, y = unique(e.df), sort = FALSE) is more readable by me.

It's an error on the help page: it should say `y'.


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