Вам не нужно использовать al oop. Вместо этого вы можете просто использовать apply
:
Некоторые данные:
mtx <- matrix(NA, nrow = 8, ncol = 4)
y <- c("yes", "no", "other")
set.seed(123)
mtx <- apply(mtx, 2, function(x) sample(y, 8, replace = T)); mtx
[,1] [,2] [,3] [,4]
[1,] "other" "other" "other" "other"
[2,] "other" "yes" "other" "no"
[3,] "other" "no" "yes" "yes"
[4,] "no" "no" "yes" "no"
[5,] "other" "yes" "yes" "other"
[6,] "no" "no" "yes" "no"
[7,] "no" "other" "other" "yes"
[8,] "no" "yes" "no" "other"
И вот как вы делаете преобразование:
apply(mtx, 2, function(x) ifelse(x=="yes"|x=="no", "maybe", x))
[,1] [,2] [,3] [,4]
[1,] "other" "other" "other" "other"
[2,] "other" "maybe" "other" "maybe"
[3,] "other" "maybe" "maybe" "maybe"
[4,] "maybe" "maybe" "maybe" "maybe"
[5,] "other" "maybe" "maybe" "other"
[6,] "maybe" "maybe" "maybe" "maybe"
[7,] "maybe" "other" "other" "maybe"
[8,] "maybe" "maybe" "maybe" "other"