[R] sort() leaves row names unaffected

Petr Pikal petr.pikal at precheza.cz
Tue Dec 14 13:17:40 CET 2004


Hi

I am not sure how you did get such result of sort and summary

Summary usually gives

> summary(titr$kys)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   1.050   1.250   1.143   1.369   2.000 

and sorting it

> y<-summary(titr$kys)
> y[1]<-5
> y[3]<-10
> y
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  5.000   1.050  10.000   1.143   1.369   2.000 
> sort(y)
1st Qu.    Mean 3rd Qu.    Max.    Min.  Median 
  1.050   1.143   1.369   2.000   5.000  10.000 

as well as

> x<-rnorm(5)*5
> names(x)<-letters[1:5]
> x
         a          b          c          d          e 
-3.8849080  1.9393499  1.8456569 -2.5334288  0.6304933 
> sort(x)
         a          d          e          c          b 
-3.8849080 -2.5334288  0.6304933  1.8456569  1.9393499 


On 14 Dec 2004 at 12:23, Martin Wegmann wrote:

Didn't you redefine something?

Cheers
Petr


> Hello, 
> 
> I wonder if I ran into a bug. If I do 
> 
> summary(df1$X1) -> df1.y
> 
> df1.y
> a  b   c   d  e
> [1,] 50.74627 8.955224 17.91045 19.40299 2.985075
> 
> sort(df1.y) 
>        a  b   c   d  e
> [1,] 2.985075 8.955224 17.91045 19.40299 50.74627
> 
> my numbers are sorted but do not anymore correspond to the rownames.
> For me it is counterintuitive that solely the numbers are sorted and
> not the names. Is there a way to sort names + numbers or is this
> behaviour of sort() unintended?
> 
> Martin
> 
> R 2.0.1-1 debian reposit.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list