Is there a way to use apply in a matrix to compare items across columns with logical operators?
n.col <- 2
A <- matrix(sample(1:6, 1000*n.col, replace = TRUE), 1000 , ncol=n.col)
For each row I would like to check if the values of across cols are the same. For small values of n.col
I just do:
A[ ,1] == A[ ,2]
But this gets pretty unwieldy for large n.cols
. I could do something ugly with a loop but I would love to know if there is some way to use apply/lapply
for this.