[Rd] Ordering of values returned by unique

From: Witold Eryk Wolski <wolski_at_molgen.mpg.de>
Date: Thu 30 Sep 2004 - 01:17:54 EST


Hi,

Is the ordering of the values returned something on what I can rely on, a form of a standard, that a function called unique in R (in futher versions) will return the uniq elements in order of they first occurcence.

> x<-c(2,2,1,2)
> unique(x)

[1] 2 1

Its seems not to be the standard. E.g. matlab  >> x=[2,2,1,2]
x =

     2 2 1 2
 >> unique(x)
ans =

     1 2

I just noted it because, the way how it is working now is extremely usefull for some applications (e.g tree traversal), so i use it in a script. But I am a little woried if I can rely on this behaviour in further versions. And furthermore can I assume that someone reading the code will think that it works in that way? Or is it better to define a additional function? keeporderunique<-function(x)
{

    res<-rep(NA,length(unique(x))
    count<-0
    for(i in x)
    {

        if(!i%in%res)
            {
                    count<-count+1
                     res[count]<-i
            }  

    }
    res
}

/E

-- 
Dipl. bio-chem. Witold Eryk Wolski         
MPI-Moleculare Genetic
Ihnestrasse 63-73 14195 Berlin           _
tel: 0049-30-83875219                   'v'
http://www.molgen.mpg.de/~wolski       /   \
mail: witek96@users.sourceforge.net  ---W-W----
      wolski@molgen.mpg.de

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Sep 30 01:23:45 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:23 EST