[R] Converting unique strings to unique numbers
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Fri May 29 19:27:21 CEST 2015
Of course, but I would not recommend it. A factor is a vector of integers with an attribute containing the labels that those integers correspond to. You seem to be asking for a factor that has lost the definitions part. But hey, newvector <- as.integer(factor(oldvector)) should get you what you asked for one column at a time.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On May 29, 2015 9:58:22 AM PDT, Kate Ignatius <kate.ignatius at gmail.com> wrote:
>I have a pedigree file as so:
>
>X0001 BYX859 0 0 2 1 BYX859
>X0001 BYX894 0 0 1 1 BYX894
>X0001 BYX862 BYX894 BYX859 2 2 BYX862
>X0001 BYX863 BYX894 BYX859 2 2 BYX863
>X0001 BYX864 BYX894 BYX859 2 2 BYX864
>X0001 BYX865 BYX894 BYX859 2 2 BYX865
>
>And I was hoping to change all unique string values to numbers.
>
>That is:
>
>BYX859 = 1
>BYX894 = 2
>BYX862 = 3
>BYX863 = 4
>BYX864 = 5
>BYX865 = 6
>
>But only in columns 2 - 4. Essentially I would like the data to look
>like this:
>
>X0001 1 0 0 2 1 BYX859
>X0001 2 0 0 1 1 BYX894
>X0001 3 2 1 2 2 BYX862
>X0001 4 2 1 2 2 BYX863
>X0001 5 2 1 2 2 BYX864
>X0001 6 2 1 2 2 BYX865
>
>Is this possible with factors?
>
>Thanks!
>
>K.
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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