Re: [R] odd feature

2006-05-22 Thread Martin Maechler
Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Sun, 21 May 2006 09:47:07 -0400 writes: Gabor If you know that test is a scalar Gabor result - if (test) a else b Gabor will do it. Yes, indeed! IMO, ifelse(test, a, b) is much overused where as if(test) a else b is

Re: [R] odd feature

2006-05-22 Thread Duncan Murdoch
On 5/22/2006 3:26 AM, Martin Maechler wrote: Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Sun, 21 May 2006 09:47:07 -0400 writes: Gabor If you know that test is a scalar Gabor result - if (test) a else b Gabor will do it. Yes, indeed! IMO, ifelse(test, a, b)

Re: [R] odd feature

2006-05-22 Thread Frank E Harrell Jr
Duncan Murdoch wrote: On 5/22/2006 3:26 AM, Martin Maechler wrote: Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Sun, 21 May 2006 09:47:07 -0400 writes: Gabor If you know that test is a scalar Gabor result - if (test) a else b Gabor will do it. Yes, indeed! IMO,

Re: [R] odd feature

2006-05-22 Thread Gabor Grothendieck
If you don't like f(if (temp) a else b) then what about temp - if (test) a else b f(temp) or temp - if (test) a else b f(temp) I think its easier to understand if you factor the temp- out since one immediately then knows the purpose of the statement is to set temp. On 5/22/06, Duncan

Re: [R] odd feature

2006-05-22 Thread Duncan Murdoch
On 5/22/2006 9:38 AM, Frank E Harrell Jr wrote: Duncan Murdoch wrote: On 5/22/2006 3:26 AM, Martin Maechler wrote: Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Sun, 21 May 2006 09:47:07 -0400 writes: Gabor If you know that test is a scalar Gabor result - if (test) a else b

Re: [R] odd feature

2006-05-22 Thread Martin Maechler
Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Mon, 22 May 2006 09:31:14 -0400 writes: Gabor If you don't like f(if (temp) a else b) Gabor then what about Gabor temp - if (test) a else b Gabor f(temp) Gabor or Gabor temp - if (test) Gabor a Gabor else

Re: [R] odd feature

2006-05-22 Thread Gabor Grothendieck
Due to lazy evaluation, I don't think a and b are fully evaluated: ifelse(1, a - 1, b - 2) [1] 1 a [1] 1 b Error: object b not found On 5/22/06, Martin Maechler [EMAIL PROTECTED] wrote: Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Mon, 22 May 2006 09:31:14 -0400 writes:

Re: [R] odd feature

2006-05-22 Thread Thomas Lumley
On Mon, 22 May 2006, Gabor Grothendieck wrote: Due to lazy evaluation, I don't think a and b are fully evaluated: ifelse(1, a - 1, b - 2) [1] 1 a [1] 1 b Error: object b not found yes. If you look at the code for ifelse() it evaluates the second argument if any test values are TRUE and

Re: [R] odd feature

2006-05-22 Thread Thomas Lumley
On Sun, 21 May 2006, ivo welch wrote: Aside, I like the flexibility of R, but I am not thrilled by all the recycling rules. I either mean I want a scalar or a vector of equal/appropriate dimension. I never want a recycle of a smaller vector. (I do often use a recycle of a scalar.) One

Re: [R] odd feature

2006-05-22 Thread Martin Maechler
TL == Thomas Lumley [EMAIL PROTECTED] on Mon, 22 May 2006 07:09:09 -0700 (PDT) writes: TL On Mon, 22 May 2006, Gabor Grothendieck wrote: Due to lazy evaluation, I don't think a and b are fully evaluated: ifelse(1, a - 1, b - 2) [1] 1 a [1] 1 b

Re: [R] odd feature

2006-05-22 Thread Gabor Grothendieck
On 5/22/06, Martin Maechler [EMAIL PROTECTED] wrote: TL == Thomas Lumley [EMAIL PROTECTED] on Mon, 22 May 2006 07:09:09 -0700 (PDT) writes: TL On Mon, 22 May 2006, Gabor Grothendieck wrote: Due to lazy evaluation, I don't think a and b are fully evaluated: ifelse(1, a -

Re: [R] odd feature

2006-05-22 Thread Uwe Ligges
Gabor Grothendieck wrote: On 5/22/06, Martin Maechler [EMAIL PROTECTED] wrote: TL == Thomas Lumley [EMAIL PROTECTED] on Mon, 22 May 2006 07:09:09 -0700 (PDT) writes: TL On Mon, 22 May 2006, Gabor Grothendieck wrote: Due to lazy evaluation, I don't think a and b are fully evaluated:

Re: [R] odd feature

2006-05-22 Thread Martin Maechler
Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Mon, 22 May 2006 11:34:09 -0400 writes: Gabor On 5/22/06, Martin Maechler [EMAIL PROTECTED] wrote: TL == Thomas Lumley [EMAIL PROTECTED] on Mon, 22 May 2006 07:09:09 -0700 (PDT) writes: TL On Mon, 22 May 2006,

Re: [R] odd feature

2006-05-22 Thread ivo welch
Hi Thomas: One case where the vector-vector recycling rules are used is in vector-matrix operations: a-1:4 b-diag(4) a+b is this last expression intended to be intuitive and thus desirable? if anything else, I would end up writing something like this more as an error than by

Re: [R] odd feature

2006-05-22 Thread Duncan Murdoch
On 5/22/2006 5:01 PM, ivo welch wrote: Hi Thomas: One case where the vector-vector recycling rules are used is in vector-matrix operations: a-1:4 b-diag(4) a+b is this last expression intended to be intuitive and thus desirable? if anything else, I would end up writing

[R] odd feature

2006-05-21 Thread ivo welch
Dear R wizards: I just got stung by the ifelse() feature. a - 10:15 b - 20:300 test - 1 ifelse(test,a,b) [1] 10 I had not realized that this was the default behavior---I had expected 10:15. mea culpa. however, I wonder whether it would make sense to replace ifelse with a different

Re: [R] odd feature

2006-05-21 Thread Gabor Grothendieck
If you know that test is a scalar result - if (test) a else b will do it. Here is another approach: as.vector(test * ts(a) + (!test) * ts(b)) On 5/21/06, ivo welch [EMAIL PROTECTED] wrote: Dear R wizards: I just got stung by the ifelse() feature. a - 10:15 b - 20:300 test - 1

Re: [R] odd feature

2006-05-21 Thread Frank E Harrell Jr
ivo welch wrote: Dear R wizards: I just got stung by the ifelse() feature. a - 10:15 b - 20:300 test - 1 ifelse(test,a,b) [1] 10 I had not realized that this was the default behavior---I had expected 10:15. mea culpa. however, I wonder whether it would make sense to replace