Tidy подход:
set.seed(234)
sample(c("09F", "09O", "xyz"), 12 * 10, replace = TRUE, prob = c(0.05, 0.05, 0.9)) %>%
matrix(ncol = 12) %>%
`colnames<-`(str_c("var", 1:12)) %>%
as_tibble() -> d
d %>%
mutate(category = map_chr(
pmap(d %>%
select(starts_with("var")),
c),
~case_when(any(.x == "09F") ~ "arts",
any(.x == "09O") ~ "arts_O",
TRUE ~ " ")))
## A tibble: 10 x 13
# var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 category
# <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
# 1 xyz xyz xyz xyz xyz xyz xyz 09O xyz xyz xyz xyz "arts_O"
# 2 xyz xyz xyz xyz 09O xyz xyz xyz xyz xyz xyz xyz "arts_O"
# 3 xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz " "
# 4 xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz " "
# 5 xyz xyz xyz xyz xyz xyz xyz xyz 09O xyz xyz xyz "arts_O"
# 6 xyz xyz xyz xyz xyz xyz xyz xyz xyz 09F xyz xyz "arts"
# 7 09O xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz "arts_O"
# 8 xyz xyz xyz xyz xyz xyz xyz xyz 09F xyz xyz xyz "arts"
# 9 09O xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz "arts_O"
#10 xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz " "
Или база R:
d$category2 <- ifelse(apply(d[grepl("var", names(d))], 1, function(x) any(x == "09F")), "arts",
ifelse(apply(d[grepl("var", names(d))], 1, function(x) any(x == "09O")), "arts_o", " "))