Re: [R] equivalent of ifelse

2009-12-09 Thread Márcio Resende
David Winsemius wrote: > > > On Dec 9, 2009, at 12:40 PM, carol white wrote: > >> Hi, >> Is there any equivalent for ifelse (except if (cond) expr1 else >> expr2) which takes an atomic element as argument but returns vector >> since ifelse returns an object of the same length as its argum

Re: [R] equivalent of ifelse

2009-12-09 Thread Duncan Murdoch
On 09/12/2009 12:40 PM, carol white wrote: Hi, Is there any equivalent for ifelse (except if (cond) expr1 else expr2) which takes an atomic element as argument but returns vector since ifelse returns an object of the same length as its argument? I don't understand what's wrong with "if (c

Re: [R] equivalent of ifelse

2009-12-09 Thread David Winsemius
On Dec 9, 2009, at 12:40 PM, carol white wrote: Hi, Is there any equivalent for ifelse (except if (cond) expr1 else expr2) which takes an atomic element as argument but returns vector since ifelse returns an object of the same length as its argument? x = c(1,2,3) y = c(4,5,6,7) z = 3 ife

Re: [R] equivalent of ifelse

2009-12-09 Thread Henrique Dallazuanna
Try this: list('TRUE' = x, 'FALSE' = y)[[as.character(as.name(z <= 1))]] On Wed, Dec 9, 2009 at 3:40 PM, carol white wrote: > Hi, > Is there any equivalent for ifelse (except if (cond) expr1 else expr2) which > takes an atomic element as argument but returns vector since ifelse returns > an ob