[R] %in% with matrix of lists
Neal H. Walfield
neal at walfield.org
Sat Jul 30 19:39:54 CEST 2016
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) <- NULL
I 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
More information about the R-help
mailing list