Unknown
0
Q:

check if a string is contained in a column R

str_detect("aecfg", letters)
grepl(letters,"aecfg")
# [1] TRUE
# Warning message:
#   In grepl(letters, "aecfg") :
#   argument 'pattern' has length > 1 and only the first element will be used
identical(str_detect("aecfg", letters),
          Vectorize(grepl,"pattern", USE.NAMES=FALSE)(letters,"aecfg")) # [1] TRUE
0
fruit <- c("apple", "banana", "pear", "pinapple")     # [1] TRUE
identical(str_detect(fruit, "a"), grepl("a",fruit))   # [1] TRUE
identical(str_detect(fruit, "^a"), grepl("^a",fruit)) # [1] TRUE
identical(str_detect(fruit, "a$"), grepl("a$",fruit)) # [1] TRUE
identical(str_detect(fruit, "b"), grepl("b",fruit))   # [1] TRUE
identical(str_detect(fruit, "[aeiou]"), grepl("[aeiou]",fruit)) # [1] TRUE
0

New to Communities?

Join the community