[R] See the numeric codes of a factor

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri Sep 19 15:49:45 CEST 2014


Sounds like a factor to me. You are just inappropriately focused on the underlying representation. Once you start using factors in regression you will get it.
---------------------------------------------------------------------------
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 September 19, 2014 5:55:42 AM PDT, Angel Rodriguez <angel.rodriguez at matiainstituto.net> wrote:
>Well, a variable with values 0/1 is useful for calculating observed
>probabilities by groups. But it is not diffcult to have the same
>variable both as numeric and as a factor in the dataframe and use each
>variation depending on the analysis.
> 
>Angel 
>
>________________________________
>
>De: Duncan Murdoch [mailto:murdoch.duncan at gmail.com]
>Enviado el: vie 19/09/2014 14:22
>Para: Angel Rodriguez; r-help at r-project.org
>Asunto: Re: [R] See the numeric codes of a factor
>
>
>
>On 19/09/2014 8:12 AM, Angel Rodriguez wrote:
>> Re: [R] See the numeric codes of a factor
>> Thank you, Duncan. So isn't it possible to add labels to a variable
>> with numeric values 0/1? This kind of variable is very useful for
>> logistic regression, for example, but I'd rather have its
>> categories labelled.
>
>I think you are thinking of how you have done things in some other
>system.  In R, a factor is fine in logistic regression, regardless of
>the fact that internally values are stored as 1 and 2.
>
>Duncan Murdoch
>
>> Angel
>>
>>
>------------------------------------------------------------------------
>> *De:* Duncan Murdoch [mailto:murdoch.duncan at gmail.com]
>> *Enviado el:* vie 19/09/2014 13:32
>> *Para:* Angel Rodriguez; r-help at r-project.org
>> *Asunto:* Re: [R] See the numeric codes of a factor
>>
>> On 19/09/2014, 6:53 AM, Angel Rodriguez wrote:
>> > Dear Subscribers,
>> >
>> > I want to label a numeric variable 0="Bad" /1="Good". I understand
>> the only way is to transform it into a factor variable.
>> >
>> > Is there a way to check that the numeric values of the new factor
>> variable are 0 and 1 and not 1 and 2?
>>
>> If you apply as.numeric() to a factor, you won't get a zero value.
>> Internal factor values start at 1.
>>
>> So I wouldn't rely on the internal storage to achieve whatever it is
>you
>> want to achieve.  Use explicit computation, e.g.
>>
>> words <- ifelse(var == 0, "Bad", ifelse(var == 1, "Good", NA))
>> values <- ifelse(words == "Bad", 0, ifelse(words == "Good", 1, NA))
>>
>> Duncan Murdoch
>>
>>
>>
>
>
>
>
>	[[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