Простая настройка будет выглядеть примерно так:
library(dplyr)
library(stringr)
subjects1 <- tibble(
col1 = c("", "", "agree"),
col2 = c("", "agree", "agree"),
col3 = c("agree", "agree", "agree"),
col4 = c("agree", "agree, agree", "agree, agree"),
col5 = c("disagree", "agree, Agree", "Neither")
)
subjects1 %>%
mutate_all(function(x) str_count(x, regex(pattern = "\\bagree\\b", ignore_case = TRUE))) %>%
colSums()
#> col1 col2 col3 col4 col5
#> 1 2 3 5 2
Создано в 2019-09-19 с помощью пакета Представить (v0.3.0)