Re: [R] Condition to factor (easy to remember)

2009-10-01 Thread Dieter Menne
Douglas Bates-2 wrote: On Wed, Sep 30, 2009 at 2:42 PM, Douglas Bates ba...@stat.wisc.edu wrote: And besides, Frank Harrell will soon be weighing in to tell you why you shouldn't dichotomize in the first place. Subjects in this study received a 20 ml infusion of Kirsch (40%, Swiss

[R] Condition to factor (easy to remember)

2009-09-30 Thread Dieter Menne
Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse construct given below most, but I remember some comment from Martin Mächler (?) that ifelse should be banned from courses. Any better idea? Not necessarily short,

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 3:43 AM, Dieter Menne wrote: Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse construct given below most, but I remember some comment from Martin Mächler (?) that ifelse should be

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread Dieter Menne
David Winsemius wrote: # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) In your code the as.integer function is superfluous Oops... done too much c# lately, getting invalid cast challenged. Dieter -- View this message in context:

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread Gabor Grothendieck
1. A common way of doing this is cut: cut(data, c(-Inf, 10, Inf), lab = levs, right = TRUE) [1] Pre Pre Pre Post Post Levels: Pre Post We don't actually need right=TRUE as its the default but if you omit it then it can be hard to remember whether the right end of intervals are included

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread Ista Zahn
An extremely verbose, but (in my view) easy to understand approach is: data.f - data; data.f[which(data = 10)] - levs[1]; data.f[which(data 10)] - levs[2]; data.f - factor(data.f) -Ista On Wed, Sep 30, 2009 at 8:31 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: David Winsemius

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:42 PM, Douglas Bates ba...@stat.wisc.edu wrote: On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students love the ifelse

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread hadley wickham
On Wed, Sep 30, 2009 at 2:32 PM, Ista Zahn istaz...@gmail.com wrote: An extremely verbose, but (in my view) easy to understand approach is: data.f - data; data.f[which(data = 10)] - levs[1]; data.f[which(data 10)] - levs[2]; data.f - factor(data.f) All those which()s are unnecessary. And

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread Peter Dalgaard
Douglas Bates wrote: On Wed, Sep 30, 2009 at 2:42 PM, Douglas Bates ba...@stat.wisc.edu wrote: On Wed, Sep 30, 2009 at 2:43 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: Dear List, creating factors in a given non-default orders is notoriously difficult to explain in a course. Students

Re: [R] Condition to factor (easy to remember)

2009-09-30 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Bates Sent: Wednesday, September 30, 2009 12:42 PM To: Dieter Menne Cc: r-help@r-project.org Subject: Re: [R] Condition to factor (easy to remember) On Wed, Sep 30