r - Inverse of which -


am missing obvious here? appears inverse function of which missing base r (googling , search on "r inverse which" returns myriad of unrelated links)?

well, not can't write one, relieve frustration being missing , r-muscle flexing challenge: how go writing one?

what need function like:

invwhich<-function(indices, totlength) 

that returns logical vector of length totlength each element in indices true , rest false.

there's bound lot of ways of accomplishing (some of low hanging fruit), argue why solution 'best'. oneliner anyone?

if takes account of other parameters of which (arr.ind??), that's better...

one-liner solution:

invwhich <- function(indices, totlength) is.element(seq_len(totlength), indices)  invwhich(c(2,5), 10) [1] false  true false false  true false false false false false 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -