search for: colchoose

Displaying 1 result from an estimated 1 matches for "colchoose".

2009 Dec 18
2
Vectorized switch
...ifelse( c('a','x','b','a') == 'a', 1:4, ifelse( c('a','x','b','a') == 'b', 11:14, 100 ) ) A simple way of doing this is (leaving aside the default case): colchoose <- function(frame,selector) mapply(function(a,b)frame[a,b],seq_along(frame[1]),selector)) colchoose( data.frame(a=1:4,b=11:14), c('a','b','b','a')) => c(1,11,11,1) But of course this is not very efficient compared to the way ifelse...