Just expanding on my comment, but the hardest part of truth tables (or any function really) is accounting for all the variations of inputs that might present. Often this is handled by error checking, essentially saying, not designed to do that or work with that. Here, the question is what's the number in the middle, so taking the elegant permutations by @Museful :
permutations <- function(n){
if(n==1){
return(matrix(1))
} else {
sp <- permutations(n-1)
p <- nrow(sp)
A <- matrix(nrow=n*p,ncol=n)
for(i in 1:n){
A[(i-1)*p+1:p,] <- cbind(i,sp+(sp>=i))
}
return(A)
}
}
my3<-matrix(c(1:3)[permutations(3)], ncol = 3)
> my3
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 3 2
[3,] 2 1 3
[4,] 2 3 1
[5,] 3 1 2
[6,] 3 2 1
# all possibles now known
if (my3[6,1] >= my3[6,2] & my3[6,2] >= my3[6,3]) print(my3[6,2])
[1] 2
> if (my3[5,1] >= my3[5,2] & my3[5,2] <= my3[5,3]) print(my3[5,3])
[1] 2
> if (my3[4,1] >= my3[4,3] & my3[4,1] <= my3[4,2]) print(my3[4,1])
[1] 2
> if (my3[3,1] >= my3[3,2] & my3[3,2] <= my3[3,3]) print(my3[3,1])
[1] 2
> if (my3[2,1] <= my3[2,2] & my3[2,2] >= my3[2,3]) print(my3[2,3])
[1] 2
> if (my3[1,1] <= my3[1,2] & my3[1,2] <= my3[1,3]) print(my3[1,2])
[1] 2
Now substitute the [,1], [,2], [,3], to a,b,c; print to return, and else between...