Hello R users When using the function which to get matches, I usually do w<-which(x==y) length(w)==0 to determine if there are matches or not. Is there a base function that can do the thing more directly by returning a logical value if the result of which is empty or not? Thanks Francois Rousseu [[alternative HTML version deleted]]
Francois -
I think you're looking for the any function:
> x = c(1,2,3)
> y = c(4,5,6)
> any(x==y)
[1] FALSE> any(which(x==y))
[1] FALSE> x = c(1,2,3)
> y = c(4,2,5)
> any(x==y)
[1] TRUE> any(which(x==y))
[1] TRUE
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Tue, 15 Feb 2011, Francois Rousseu wrote:
>
> Hello R users
>
> When using the function which to get matches, I usually do
>
> w<-which(x==y)
> length(w)==0
>
> to determine if there are matches or not. Is there a base function that can
do the thing more directly by returning a logical value if the result of which
is empty or not?
>
> Thanks
> Francois Rousseu
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
I would use match() ?match Rich On Tue, Feb 15, 2011 at 2:11 PM, Francois Rousseu < francoisrousseu@hotmail.com> wrote:> > Hello R users > > When using the function which to get matches, I usually do > > w<-which(x==y) > length(w)==0 > > to determine if there are matches or not. Is there a base function that can > do the thing more directly by returning a logical value if the result of > which is empty or not? > > Thanks > Francois Rousseu > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]