a row operation that will form a vector of the first match of a pattern.

icd_first_valid_regex(data, colvec, pattern)

Arguments

data

input data

colvec

selected columns to match

pattern

the pattern to match

Value

return the vector of the matched characters with NA for a no match

Examples

dat <- data.frame(x1 = letters[1:3], x2 = c("d", "a", "e")) library(dplyr) library(purrr) dat %>% mutate(x3 = icd_first_valid_regex(., colvec = c(1:2), pattern = "a"))
#> x1 x2 x3 #> 1 a d a #> 2 b a a #> 3 c e <NA>