Skip to content
Back to formatted view

Raw Message

Message-ID: <m2r76mbvjy.fsf@fhcrc.org>
Date: 2006-02-01T21:47:45Z
From: Seth Falcon
Subject: strange question...
In-Reply-To: <E97312684A84D511BDD40002A50968D6071705D3@lxpobw01.ine.pt> (Ana Patricia Martins's message of "Wed, 1 Feb 2006 14:37:33 -0000")

On  1 Feb 2006, ana.pmartins at 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