Answers for "check if a string is contained in a column R"

0

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
Posted by: Guest on May-26-2020
0

check if a string is contained in a column R

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
Posted by: Guest on May-26-2020

Code answers related to "check if a string is contained in a column R"

Browse Popular Code Answers by Language