[R] Recategorizing Nominal variable

R. Michael Weylandt michael.weylandt at gmail.com
Tue Sep 25 17:28:26 CEST 2012


On Tue, Sep 25, 2012 at 2:22 PM, Michael Leitson
<Michael.Leitson at wellstar.org> wrote:
> Hello,
>
> I would like to take a data set of doctors, and recategorize them into
> numbers.
>
> For example,
>
> John Doe would be assigned as 1
> Jane Doe would be assigned as 2
>
> Does anyone know how to do this in R? It seems quite easy, yet I cannot
> find the code.
>
> Thank you,
>
>

Try something like

as.numeric(factor(x))

This works because factors are internally coded as one integer per
unique level.

Cheers,
Michael

> Michael Leitson
>
> Research Intern
> MSAS Candidate
> Michael.Leitson at wellstar.org
>
>
> ________________________________________________
> This email and any files transmitted with it may contain
> confidential and /or proprietary information in the possession
> of WellStar Health System, Inc. ("WellStar") and is intended
> only for the individual or entity to whom addressed. This email
> may contain information that is held to be privileged, confidential
> and exempt from disclosure under applicable law. If the reader
> of this message is not the intended recipient, you are hereby
> notified that any unauthorized access, dissemination, distribution
> or copying of any information from this email is strictly prohibited,
> and may subject you to criminal and/or civil liability. If you have
> received this email in error, please notify the sender by reply email
> and then delete this email and its attachments from your computer.
> - Thank you.
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.




More information about the R-help mailing list