[R] Unable to specify order of a factor
Sarah Goslee
sarah.goslee at gmail.com
Wed Mar 21 15:59:28 CET 2012
Ah, you're missing something crucial:
> levels(total.density)
[1] "8" "16" "32"
is giving you the *labels* of the factor, as *strings*, and what you
get if you use order() on them has nothing to do with the order of the
factor levels, and everything to do with the string sort order for
your locale.
> str(levels(total.density))
chr [1:3] "8" "16" "32"
The factor levels themselves are in the order you specified.
> str(total.density)
Ord.factor w/ 3 levels "8"<"16"<"32": 1 1 1 1 1 1 1 1 1 1 ...
On Wed, Mar 21, 2012 at 10:50 AM, Justin Montemarano <jmontema at kent.edu> wrote:
> Actually I've try that too, Sarah....
>
> The test is to run order(levels(total.density)), which I need to be 1 2 3,
> not 2 3 1, and your solution still gives me 2 3 1.
>
> I also don't know how to reply to this thread with the previous message
> below...
> -
> Justin Montemarano
> Graduate Student
> Kent State University - Biological Sciences
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list