[R] Sorting factors

From: tom sgouros <tomfool_at_as220.org>
Date: Fri, 21 Dec 2007 10:34:23 -0500

Hello all:

I'm sorry to take up bandwidth with easy questions, but as an R beginner, I continue to be surprised by factors. If someone can shed some light for me, I'd be grateful:

> d

 Total z02801 z02802 z02804 z02806 z02807 z02808 z02809 z02812 z02813  54813 29 51 169 2368 103 76 1328 112 501 507 Levels: 0 10 1001 1004 1008 1016 1027 1028 103 1031 10318 1043 1045 ... Na
> sort(d)

z02807 z02812 z02809 z02804 z02806 z02801 z02813 z02802 Total z02808

   103 112 1328 169 2368 29 501 51 54813 76 507 Levels: 0 10 1001 1004 1008 1016 1027 1028 103 1031 10318 1043 1045 ... Na

Apparently this factor is sorted in alphabetic order, not numeric order. I find no parameter of sort() that controls for this.

And yet:

> mode(d)

[1] "numeric"
> length(d)

[1] 10

I would have thought that because d is a numeric list of ten values, I'd get them sorted in numeric order.

Can someone help me understand why this is expected behavior, and also what I should do in order to see the numerically sorted list of values I really want?

Many thanks,

 -tom

-- 
 ------------------------
 tomfool at as220 dot org
 http://sgouros.com  
 http://whatcheer.net

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 21 Dec 2007 - 15:50:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Dec 2007 - 16:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.