Poisson
Poisson

Reputation: 1623

Check if at least one element of a list is a contained in a list with R

I try to check if at least there is one element of a list var2 is a contained in the list booster_word. For this I use :

any(var2 %in% booster_word)

But it is incorrect.

Example :

 > var2
    [[1]]
    [1] "served" "both"   "as"    

    > booster_word
     [1] "more"       "very"       "too"        "much"       "completely" "absolutely" "fully"      "totally"    "definitely" "extremely" 
    [11] "often"      "frequently" "enough"     "a lot"      "as"        
    > any(var2 %in% booster_word)
    [1] FALSE

Any idea please?

Thank you

Upvotes: 1

Views: 1149

Answers (1)

akrun
akrun

Reputation: 887511

We can convert the list to a vector with [[ as it is of length 1.

 any(var2[[1]] %in% booster_word)

Upvotes: 1

Related Questions