jack - 5 months ago 26

R Question

Suppose I have two vectors, A and B. I want to get a boolean vector with the same length of vector A, which tells the information of each element in vector A whether it is in vector B. What is the function for it?

Answer

I think you're looking for `%in%`

:

```
A <- c(0,2,4,6)
B <- c(8,7,6,5,4)
A %in% B
[1] FALSE FALSE TRUE TRUE
```