your apply says to take each cell in turn MARGINS=c(1,2) and apply a function that expects a matrix input ; but its not a matrix input, its a scalar value, the value of a cell of your matrix input

matrix .mat is a 2x3 matix
I want to work on only first 2 columns ; let's call it matrix2
Then I want to compute error rate using function seen in the code.

Doing it this way allows for computing the error rate for a matrix of three variables (matrix3).
matrix3 <- {a b c, d e f,g h i}.
I have not worked with such a problem but it seems reasonable that off diagonal elements are components of misclassification.

Subsetting is exactly what I wanted to do. I was getting confused with the 1:2 referring to rows and columns of the subsetted matrix and the 1:2 in the apply statement.

I'm finding the apply statement to be confusing but I'm continuing to work at its interpretation.