split , list of data.frame , "" , max.col
data.frame(lapply(split.default(df, sub("[a-z]+$", "", names(df))), function(x) {
i1 <- x[,1] == "other"
i2 <- x[-1] != "other" & !is.na(x[-1])
x[,1][i1] <- x[-1][cbind(1:nrow(i2), (max.col(i2))* i1)]
x[,1]
}))
tidyverse
library(dplyr)
library(purrr)
split.default(df, sub("[a-z]+$", "", names(df))) %>%
map_df(~ replace(., .== 'other', NA) %>%
do.call(paste, .) %>%
gsub("\\s*|(NA\\s*)+", "", .))