Skip to content

Searching elements in list

3 messages · mstepano, David Winsemius

#
Hi all,

I have a list ov vectors of enequal lenght and need to check is the given
vector in list.
[1] FALSE FALSE

Hence, %in% checks that elements of vector somev are in list. How it is
possible to check that somev is element of list? 

--
View this message in context: http://r.789695.n4.nabble.com/Searching-elements-in-list-tp3987066p3987066.html
Sent from the R help mailing list archive at Nabble.com.
#
On Nov 3, 2011, at 3:21 PM, mstepano wrote:

            
all.equal worked fine when the answer was 'true' but not so well in my  
hands when it was 'false'. Also not a good idea to replace the base  
definition of %in%.

 > any( sapply( allv, identical, v1) )
[1] TRUE
 > any( sapply( allv, identical, c(3,3,4)) )
[1] FALSE

`%l.in%` <- function(vec,lis) any( sapply( lis, identical, vec) )

Use:
 > v1 %l.in% allv
[1] TRUE

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT