Re: [Rd] Vectorized switch

From: Stavros Macrakis <macrakis_at_alum.mit.edu>
Date: Fri, 18 Dec 2009 14:48:12 -0500

On Fri, Dec 18, 2009 at 2:39 PM, William Dunlap <wdunlap_at_tibco.com> 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 right. I edited my test case and didn't change the results -- my apologies!

> However, if you want c(1,12,13,4) one approach is to use
> a 2-column matrix of integers as the subscript into the
> main matrix (or data.frame).

Thanks! That makes sense. This looks like a good way of doing things.

            -s

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 18 Dec 2009 - 19:52:19 GMT

This archive was generated by hypermail 2.2.0 : Fri 18 Dec 2009 - 20:51:10 GMT