Один из вариантов - создать именованный вектор, соответствующий значениям в каждом из столбцов и unite
столбцам
library(dplyr)
library(tidyr)
df1 %>%
mutate_all(~ setNames(c('Federal', "Private", "Other", "Tribal"),
c("F", "P", "O", "T"))[.]) %>%
unite(alllType, everything(), sep=", ") %>%
bind_cols(df1, .)
# A tibble: 4 x 4
# `Land Type` `Owner Type` `Operator Type` alllType
#* <chr> <chr> <chr> <chr>
#1 F P F Federal, Private, Federal
#2 F F F Federal, Federal, Federal
#3 F P O Federal, Private, Other
#4 T F P Tribal, Federal, Private
Если нам не нужны повторяющиеся записи,
library(purrr)
df1 %>%
mutate_all(~ setNames(c('Federal', "Private", "Other", "Tribal"),
c("F", "P", "O", "T"))[.]) %>%
transmute(allType = pmap_chr(., ~ toString(unique(c(...))))) %>%
bind_cols(df1, .)
# A tibble: 4 x 4
# `Land Type` `Owner Type` `Operator Type` allType
#* <chr> <chr> <chr> <chr>
#1 F P F Federal, Private
#2 F F F Federal
#3 F P O Federal, Private, Other
#4 T F P Tribal, Federal, Private
данные
df1 <- structure(list(`Land Type` = c("F", "F", "F", "T"), `Owner Type` = c("P",
"F", "P", "F"), `Operator Type` = c("F", "F", "O", "P")), row.names = c(NA,
-4L), class = c("tbl_df", "tbl", "data.frame"))