Re: [R] How to avoid ifelse statement converting factor to character

2011-11-04 Thread David Winsemius
On Nov 4, 2011, at 7:33 PM, clint wrote: > most all those posts were right in sourcing the problemits just that > nobody actually offered a viable solution Very few problems that are posed with a test dataset go unanswered. > > the problem is that the new level "C" was not one of the

Re: [R] How to avoid ifelse statement converting factor to character

2011-11-04 Thread clint
most all those posts were right in sourcing the problemits just that nobody actually offered a viable solution the problem is that the new level "C" was not one of the original levels in $social status add "C" as a level and then just do the ol fashioned way and it works just fine do this: d

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame
Dear Peter, Thank you for the explanations. Some further questions are inlined below. Best regards, Craig Peter Dalgaard wrote: Craig P. Pyrame wrote: Stavros Macrakis wrote: It gives me a headache, too! I think you'll have to wait for a more expert user than me to supply explanations of th

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Peter Dalgaard
Craig P. Pyrame wrote: Stavros Macrakis wrote: It gives me a headache, too! I think you'll have to wait for a more expert user than me to supply explanations of these behaviors and their rationales. Thanks, Stavros. I hope someone with expertise will shed more light on this, and in the m

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame
Stavros Macrakis wrote: It gives me a headache, too! I think you'll have to wait for a more expert user than me to supply explanations of these behaviors and their rationales. Thanks, Stavros. I hope someone with expertise will shed more light on this, and in the meantime I'll try to lear

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Stavros Macrakis
It gives me a headache, too! I think you'll have to wait for a more expert user than me to supply explanations of these behaviors and their rationales. -s On 6/26/09, Craig P. Pyrame wrote: > Stavros Macrakis wrote: >> On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyrame >> wrote: >>

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Craig P. Pyrame
Stavros Macrakis wrote: On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyrame wrote: The man page Stavros quotes states that the class attribute of the result is taken from 'test', which clearly is not the case: Actually, the behavior is documented pretty clearly: The mode of the ans

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyrame wrote: > The man page Stavros quotes states that the class attribute of the result is > taken from 'test', which clearly is not the case: Actually, the behavior is documented pretty clearly: The mode of the answer will be coerced from logical

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Craig P. Pyrame
Dear Rolf, Rolf Turner wrote: On 25/06/2009, at 12:27 PM, Craig P. Pyrame wrote: Dear Stavros, What you discuss below is somewhat scary to me as an R newbie. Is this just an incident, a bug perhaps, or rather the way things typically go in R, as your "Welcome to R!" seems to suggest? I ha

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
Erratum: >     ifelse(TRUE,dd,dd) => 1230786000 (class numeric) should be ifelse(TRUE,tt,tt) => 1230786000 (class numeric) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
On Wed, Jun 24, 2009 at 9:04 PM, Rolf Turner wrote: >  Do not get your knickers in a twist.  R works simply and straightforwardly >  in simple straightforward situations. Though I find R an incredibly useful tool, alas, it is simply not true that "R works simply and straightforwardly in simple str

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Patrick Burns
This sort of experience is why 'The R Inferno' came into existence. Patrick Burns patr...@burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") Craig P. Pyrame wrote: Dear Stavros, What you discuss below is somewhat scar

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Rolf Turner
On 25/06/2009, at 12:27 PM, Craig P. Pyrame wrote: Dear Stavros, What you discuss below is somewhat scary to me as an R newbie. Is this just an incident, a bug perhaps, or rather the way things typically go in R, as your "Welcome to R!" seems to suggest? I have just started to learn R

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Craig P. Pyrame
Dear Stavros, What you discuss below is somewhat scary to me as an R newbie. Is this just an incident, a bug perhaps, or rather the way things typically go in R, as your "Welcome to R!" seems to suggest? I have just started to learn R, and my initial euphoria of the "I can do anything with

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Stavros Macrakis
On Wed, Jun 24, 2009 at 12:34 PM, Mark Na wrote: > The problem is that after running the ifelse statement, data$SOCIAL_STATUS > is converted from a factor to a character. > Is there some way I can avoid this conversion? I'm afraid that ifelse has very bizarre semantics when the yes and no argument

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Bert Gunter
Sent: Wednesday, June 24, 2009 9:34 AM To: r-help@r-project.org Subject: [R] How to avoid ifelse statement converting factor to character Hi R-helpers, Please see the below R output. The problem is that after running the ifelse statement, data$SOCIAL_STATUS is converted from a factor to a charac

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Henrique Dallazuanna
You can work with levels of factor: levels(DF$SOCIAL_STATUS)[DF$MALE > 4 & DF$SOCIAL_STATUS == "B"] <- "C" On Wed, Jun 24, 2009 at 1:34 PM, Mark Na wrote: > Hi R-helpers, > > Please see the below R output. > The problem is that after running the ifelse statement, data$SOCIAL_STATUS > is convert

[R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Mark Na
Hi R-helpers, Please see the below R output. The problem is that after running the ifelse statement, data$SOCIAL_STATUS is converted from a factor to a character. Is there some way I can avoid this conversion? Thanks in advance, Mark Na > str(data) 'data.frame': 2100 obs. of 11 variables: $ D