Re: [Rd] Vectorized switch

2009-12-18 Thread Gabriel Becker
On Fri, Dec 18, 2009 at 11:49 AM, wrote: > On Fri, 18 Dec 2009, Gabriel Becker wrote: > > My understanding is that all the really fast vectorized operations are >> implemented down in C code, not in R. Thus if you wanted to write a >> vectorized switch, which I agree would be rather nice to have

Re: [Rd] Vectorized switch

2009-12-18 Thread tlumley
On Fri, 18 Dec 2009, Gabriel Becker wrote: My understanding is that all the really fast vectorized operations are implemented down in C code, not in R. Thus if you wanted to write a vectorized switch, which I agree would be rather nice to have, you'd need to do it down there and then write a .Ca

Re: [Rd] Vectorized switch

2009-12-18 Thread Stavros Macrakis
On Fri, Dec 18, 2009 at 2:39 PM, William Dunlap wrote: > > colchoose( data.frame(a=1:4,b=11:14), c('a','b','b','a')) > >=> c(1,11,11,1) > > I thought you would want c(1,12,13,4), not c(1,11,11,1), > out of this call. Perhaps I misunderstand your requirements. > Sorry, you're r

Re: [Rd] Vectorized switch

2009-12-18 Thread William Dunlap
> -Original Message- > From: r-devel-boun...@r-project.org > [mailto:r-devel-boun...@r-project.org] On Behalf Of Stavros Macrakis > Sent: Friday, December 18, 2009 11:07 AM > To: r-devel@r-project.org > Subject: [Rd] Vectorized switch > > What is the 

Re: [Rd] Vectorized switch

2009-12-18 Thread Gabriel Becker
My understanding is that all the really fast vectorized operations are implemented down in C code, not in R. Thus if you wanted to write a vectorized switch, which I agree would be rather nice to have, you'd need to do it down there and then write a .Call wrapper for it in R. The ifelse (C) code w

[Rd] Vectorized switch

2009-12-18 Thread Stavros Macrakis
What is the 'idiomatic' way of writing a vectorized switch statement? That is, I would like to write, e.g., vswitch( c('a','x','b','a'), a= 1:4, b=11:14, 100 ) => c(1, 100, 13, 4 ) equivalent to ifelse(