Re: [Rd] Getting ordered factor levels from C

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Wed, 24 Oct 2012 16:16:54 -0400

On Oct 24, 2012, at 2:14 PM, Mark Lilback wrote:

> I'm working on an R package in C and can't seem to get the same level information about a factor that the R console displays.
>
> If I define a factor as:
>
> lvls <- factor(c('red','blue','blue','green','red'), c('blue','green','red'), ordered=TRUE)
>
> When I get the "levels" attribute in C, I get back the the first vector, not the second.

What are you using in C? AFAICS it works just fine:

> f=cfunction(c(foo="factor"), "return getAttrib(foo, R_LevelsSymbol);")
> f(lvls)

[1] "blue" "green" "red"

Cheers,
Simon

> If I run attr(lvls,"levels") in R, I get back the second vector. There are no attributes besides class and levels, so how do I get the list of levels in the correct order?
>
> Thanks
>
> --
> Mark Lilback
> West Virginia University Department of Statistics
> mlilback_at_stat.wvu.edu
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 24 Oct 2012 - 20:21:18 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Thu 25 Oct 2012 - 09:41:21 GMT.

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

list of date sections of archive