Re: [R] strange question...

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Thu 02 Feb 2006 - 08:47:45 EST

On 1 Feb 2006, ana.pmartins@ine.pt wrote:
> am$e_isell <- factor( with( am, ifelse( e_iacc == 1 & C5 == 1, 1,
> 0)))
>
>
> cbind( am$e_isell[4256], am$C6[4256])
>
> [,1] [,2]
>
> [1,] "2" "1"
>
>
>
> (????????????? :( )
>
>
>
> Does anyone understand why this happens?

A factor is an integer vector with levels. Although there are many operations one can perform on a factor that will "work" because of automagic convertion of the factor to its underlying integer vector, it is rarely useful, IMHO.

The following may help you see what is going on:

f = factor(c(0, 1, 1, 0))

unclass(f)

as.numeric(f)
as.integer(f)

as.character(f)
as.integer(as.character(f))

+ seth



R-help@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 Received on Thu Feb 02 08:55:35 2006

This archive was generated by hypermail 2.1.8 : Thu 02 Feb 2006 - 20:22:08 EST