[R] converting a factor in numeric values with direct control of the numeric values

ronggui ronggui.huang at gmail.com
Sat Jan 17 17:44:44 CET 2009


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ß <joerg at licht-malerei.de> 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 convert male in 3 and female into the numeric value 5 (just
> for the example)
>
> so that I get:
>
> [1] 3 3 5
>
>
> Thanks for any help!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
HUANG Ronggui, Wincent
Tel: (00852) 3442 3832
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Homepage: http://ronggui.huang.googlepages.com/




More information about the R-help mailing list