[R] merge: How to preserve the original order?

Wolfram Fischer - Z/I/M wolfram at fischer-zim.ch
Fri Oct 25 10:02:39 CEST 2002


I tried:
    x.vals <- data.frame(
          id = c( 'A1', 'C2', 'B3' )
        , ref = c( 'Ref1', 'Ref2' ,'Ref1' )
        , val = c( 1.11, 2.22, 3.33 )
        )
    x.labels <- data.frame(
          ref = c( 'Ref1', 'Ref2' )
        , label = c( 'Label01', 'Label02' )
        )

    merge( x.vals, x.labels, by='ref', all.x = T, sort=F )

I received:
         ref  id  val   label
    1   Ref1  A1 1.11 Label01
    2   Ref1  B3 3.33 Label01
    3   Ref2  C2 2.22 Label02

Alltough 'sort=F' is set, the original order: id = A1, C2, B3 is
not preserved. - Is there a possibility to preserve the original
order (when there is no key field which can be ordered after merging).
(Perhaps 'merge' is not the right solution for this problem?)

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