1
vec1<- c(4)
vec2<-c(1,3,4,5)
vec1==vec2

output:[1] FALSE FALSE TRUE FALSE

expected output: [1] TRUE

I want to return "TRUE" once only if a single value in vec2 is equal to a value in vec1... how to do this?

1 Answers1

2

We can wrap with any to check for any TRUE element

any(vec1 == vec2)
#[1] TRUE

Or instead of ==, use %in%, which returns the length of the object on the lhs of %in%

vec1 %in% vec2
#[1] TRUE
akrun
  • 874,273
  • 37
  • 540
  • 662