On Sat, 30 Jul 2016 19:28:42 +0200, Bert Gunter wrote:> Bottom line: No, I dont see any vectorized way to do this. > > However, the following may offer some slight improvement over your approach. > > 1. Why do you need to store these as arrays, which are merely vectors > with a "dim" attribute? > > ## convert to vectors (a list is also a vector): > > dim(x) <- NULL; dim(y) <- NULLI apologize that my example was not minimal. I have the data stored in an array for other reasons.> 2. ... and use mapply() instead of sapply() (not clear to me *how* > you mean to use sapply() anyway)Sorry, I meant (and I'm using) mapply.> > mapply("%in%",y,x) ## might be slightly faster to use match() directly > > [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F)I'm not sure what you mean by NOT here. You get the same answer as I do, as far as I can see. Thanks for your help! :) Neal
>> [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F) > >I'm not sure what you mean by NOT here. You get the same answer as I >do, as far as I can see. ># valid R T <- FALSE # invalid R TRUE <- FALSE It is much much safer and clearer to use TRUE/FALSE than T/F. So c( TRUE, FALSE, TRUE, FALSE ) may not always be the same as c(T,F,T,F). I recommend reading the R Inferno to learn about this other such pitfalls. -- Sent from my phone. Please excuse my brevity.
On Sat, 30 Jul 2016 20:35:40 +0200, Jeff Newmiller wrote:> > >> [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F) > > > >I'm not sure what you mean by NOT here. You get the same answer as I > >do, as far as I can see. > > > > # valid R > T <- FALSE > # invalid R > TRUE <- FALSE > > It is much much safer and clearer to use TRUE/FALSE than T/F. So > > c( TRUE, FALSE, TRUE, FALSE ) may not always be the same as c(T,F,T,F).I see. I was just trying to create a minimal example. I'll try to be more vigorous next time!> I recommend reading the R Inferno to learn about this other such pitfalls.Thanks for the tip!