Closed iDudeRPS closed 1 year ago
Hi! Thanks for reaching out.
The %like%
function works the same as the base R grepl()
function - it does not allow different sizes between what you look for (pattern
) and where you look in (x
). You can do it in two ways:
Use a regular expression to combine the two
df %>% filter(microbe_short %like% "baum|stiarum")
# or:
test2 <- c("baum", "stiarum")
df %>% filter(microbe_short %like% paste0(test2, collapse = "|"))
Use if_any()
from the dplyr
package: https://dplyr.tidyverse.org/reference/across.html
I'm not sure about the second option, but the first should work!
Thanks!
I assume this can be closed 😊
hai
great update! very significant speed improvement of as.mo !!
I have a question: how can I use %like% to search in a vector ?
for example:
test1 <- c("A. baumannii", "A. bestiarum") test2 <- c("baum", "stiarum")
df %>% filter(microbe_short %in% test1) #I can use this
df %>% filter(microbe_short %like% test2) #but this doesn't work
Is there a way to use %like% to search in a column for matching values?
thanks!