I am trying to check whether nesed lists contain elements of a vector.
My result with str_detect is pretty close, but what I want is simply a vector for the lists (TRUE TRUE FALSE) and not the results for each element in the list (as I have now).
I assume I am lacking a subsequent step?
I am alson not clear why I am getting the warning with str_detect.
Many thanks!
library(tidyverse)
x <- list(list1=c("a","A","y"),
list2=c("b","B","y"),
list3=c("c", "C","y"))
y <- c("a","B")
map(x, ~str_detect(., y))
EDIT: i just realised that my approach above is actually wrong. If the sequence in y would be c("B", "a")
the result contains no TRUE. So the command is contingent on the sequence, and this should not be the case.
#> Warning in stri_detect_regex(string, pattern, opts_regex = opts(pattern)):
#> longer object length is not a multiple of shorter object length
#> Warning in stri_detect_regex(string, pattern, opts_regex = opts(pattern)):
#> longer object length is not a multiple of shorter object length
#> Warning in stri_detect_regex(string, pattern, opts_regex = opts(pattern)):
#> longer object length is not a multiple of shorter object length
#> $list1
#> [1] TRUE FALSE FALSE
#>
#> $list2
#> [1] FALSE TRUE FALSE
#>
#> $list3
#> [1] FALSE FALSE FALSE
map(x, ~has_element(., y))
#> $list1
#> [1] FALSE
#>
#> $list2
#> [1] FALSE
#>
#> $list3
#> [1] FALSE