ronggui wrote:
I think you have to recode the derived variable of as.numeric(z).
The easiest way is probably to use indexing:
> z <- c("male", "male", "female")
> z <- factor(z)
> c(5,3)[z]
[1] 3 3 5
or, slightly more foolproof
> c(male=3,female=5)[as.character(z)]
male male female
On Sat, 17 Jan 2009, Charles C. Berry wrote:
On Sat, 17 Jan 2009, J?rg Gro? wrote:
Hi,
I know how to convert a factor-variable into a numeric variable via
as.numeric().
But how can I control the values that are assigned?
For example, I have this factor-variable:
z <- c("male", "mal
ifelse is your friend:
> z <- c("male", "male", "female")
> z <- as.factor(z)
>
> z <- ifelse(z == "male", 3, 5)
> z
[1] 3 3 5
> class(z)
[1] "numeric"
>
--
David Winsemius
On Jan 17, 2009, at 11:40 AM, Jörg Groß wrote:
Hi,
I know how to convert a factor-variable into a numeric variabl
On Sat, 17 Jan 2009, J?rg Gro? wrote:
Hi,
I know how to convert a factor-variable into a numeric variable via
as.numeric().
But how can I control the values that are assigned?
For example, I have this factor-variable:
z <- c("male", "male", "female")
z <- as.factor(z)
And I want to con
BTW, a better way to convert factor into a numeric variable is to use
unclass().
On Sun, Jan 18, 2009 at 12:40 AM, Jörg Groß wrote:
> Hi,
>
> I know how to convert a factor-variable into a numeric variable via
> as.numeric().
>
> But how can I control the values that are assigned?
>
>
> For exam
I think you have to recode the derived variable of as.numeric(z).
On Sun, Jan 18, 2009 at 12:40 AM, Jörg Groß wrote:
> Hi,
>
> I know how to convert a factor-variable into a numeric variable via
> as.numeric().
>
> But how can I control the values that are assigned?
>
>
> For example, I have this
Hi,
I know how to convert a factor-variable into a numeric variable via
as.numeric().
But how can I control the values that are assigned?
For example, I have this factor-variable:
z <- c("male", "male", "female")
z <- as.factor(z)
And I want to convert male in 3 and female into the nume
7 matches
Mail list logo