Your code works if you write two nested loops:
for(i in 1:10} {
for (j in 1:10) {
if vector[j] == vector2[i]
print(variable)
else
print(NA)
}
}
The following example shows a different possibility to obtain this result more quickly:
set.seed(1234)
vector <- sample(20,10)
vector2 <- sample(20,10)
same <- vector[vector %in% vector2]
m <- matrix(NA,ncol=10,nrow=10)
for (i in 1:length(same)) m[vector==same[i], vector2==same[i]] <- same[i]
#> vector
# [1] 3 12 11 18 14 10 1 4 8 6
#> vector2
# [1] 14 11 6 16 5 13 17 4 3 12
#> m
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
# [1,] NA NA NA NA NA NA NA NA 3 NA
# [2,] NA NA NA NA NA NA NA NA NA 12
# [3,] NA 11 NA NA NA NA NA NA NA NA
# [4,] NA NA NA NA NA NA NA NA NA NA
# [5,] 14 NA NA NA NA NA NA NA NA NA
# [6,] NA NA NA NA NA NA NA NA NA NA
# [7,] NA NA NA NA NA NA NA NA NA NA
# [8,] NA NA NA NA NA NA NA 4 NA NA
# [9,] NA NA NA NA NA NA NA NA NA NA
#[10,] NA NA 6 NA NA NA NA NA NA NA
#> same
#[1] 3 12 11 14 4 6
The advantage is here that you have just one small loop that runs only over those entries which are equal in both vectors (six numbers in this case), instead of the nested loops which run over the entire 100 entries of the matrix.
If you want to print the entries of this matrix sequentially, like in your nested loops, you can type:
print(c(m))
As far as the changes connected with your edit are concerned, I assume that this should work:
same1 <- st231_eq1_alg$Output[st231_eq1_alg$Output %in% st231_eq1_alg$Input]
idx2 <- which(duplicated(st231_eq1_alg$Output))
same2 <- st231_eq1_alg$Output[idx2]
m <- matrix(NA, ncol = 10, nrow = 10)
for(i in 1:length(same1)) m[st231_eq1_alg$Output==same1[i], st231_eq1_alg$Input==same1[i]] <- same1[i]
for(i in 1:length(same2)) m[st231_eq1_alg$Output==same2[i], st231_eq1_alg$Output==same2[i]] <- st231_eq1_alg_inv_f[idx2[i]]
print(c(m))