Re: [R] problems with coercing a factor to be numeric

2013-01-24 Thread Francesco Sarracino
Dear Ellison, thanks a lot for your reply. Your explanation makes things much clearer. Sincerely, f. On 24 January 2013 05:58, S Ellison wrote: > > > On 23 Jan 2013, at 21:36, "Francesco Sarracino" > wrote: > > > what I meant refers to the fact that I've read on "an R and > > S-plus co

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread S Ellison
On 23 Jan 2013, at 21:36, "Francesco Sarracino" wrote: > what I meant refers to the fact that I've read on "an R and > S-plus companion to applied regression" about methods to alter the encoding > of factors when using contrasts in regressions. These are options (for > contrasts) that ca

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread Francesco Sarracino
Thank you all for your replies. Let me try to explain my point: first of all, let me clarify that I didn't mean to criticize anyone (or anything). Secondly, what I meant refers to the fact that I've read on "an R and S-plus companion to applied regression" about methods to alter the encoding of f

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread Rolf Turner
Given that your labels are "no" and "yes", what do you expect R to do? To quote a well-known fortune, "R is lacking a mind_read() function!" cheers, Rolf Turner On 01/23/2013 10:58 PM, Francesco Sarracino wrote: Thanks, this works! but I am surprised that R has such a strange beh

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread William Dunlap
gt; From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Francesco Sarracino > Sent: Wednesday, January 23, 2013 1:59 AM > To: D. Rizopoulos > Cc: R help > Subject: Re: [R] problems with coercing a factor to be numeric > > Thanks,

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread David Winsemius
On Jan 23, 2013, at 1:58 AM, Francesco Sarracino wrote: Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help.

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread Francesco Sarracino
Thanks, this works! but I am surprised that R has such a strange behavior and that there is no way to control it. BTW, also as.integer(pp)-1 works! Still, it doesn't look to me as a first best. At any rate, thanks a lot for your help. f. On 23 January 2013 10:53, D. Rizopoulos wrote: > check al

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread D. Rizopoulos
check also pp <- rep(0:1, 10) pp <- factor(pp, levels=(0:1), labels=c("no","yes")) unclass(pp) unclass(pp) - 1 Best, Dimitris On 1/23/2013 10:48 AM, Francesco Sarracino wrote: > Dear Dimitris, > > thanks for your quick reply. I've tried the solutions proposed in 7.10 > How do I convert factor

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread Francesco Sarracino
Dear Dimitris, thanks for your quick reply. I've tried the solutions proposed in 7.10 How do I convert factors to numeric? as.numeric(as.character(pp)) and as.numeric(levels(pp))[as.integer(pp)] However, whatever I do, I get "Warning message: NAs introduced by coercion" and the output is a vecto

Re: [R] problems with coercing a factor to be numeric

2013-01-23 Thread D. Rizopoulos
Check R FAQ 7.10: How do I convert factors to numeric? I hope it helps. Best, Dimitris On 1/23/2013 10:33 AM, Francesco Sarracino wrote: > Dear R listers, > > I am trying to compute the mean of a dummy variable that is encoded as a > factor. However, even though the levels of my factor are 0 -

[R] problems with coercing a factor to be numeric

2013-01-23 Thread Francesco Sarracino
Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please,