[R] accessing factor levels from C

Ott Toomet siim at obs.ee
Sat Mar 2 15:43:59 CET 2002


Hi,

I am trying to get information about factors from a C-program.  As I see,
the factors are basically integers with attribute ,,levels''.  But
unfortunately I am not been able to read the levels information.  I am
using:

SEXP variable, levels;

...

      variable = VECTOR_ELT( data_frame, j);
      switch( TYPEOF( variable)) {
      case INTSXP:
	if( isFactor( VECTOR_ELT( data_frame, j))) {
	  fvalue = INTEGER( variable)[i];
	  levels = STR_PTR( GET_LEVELS( variable));
	....


but the variable levels is not an array of strings as I expected.  I am
probably doing something in the wrong way but how would it be correct?

Thanks in advance,

Ott Toomet

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list