Comparing and counting sign of elements in two matrics


New Member
I have two giant matrices (5000x6000) each. I want to compare the sign of elements of two matrices without doing a for loop kind of thing. And then I want to count how many had the matching sign.

I did find ways to compare whether two are identical but couldn't find anything which can do the above.

Thanks guys


Ambassador to the humans
You definitely don't want to do this in a loop

# make fake matrices

nrow <- 4
matA <- matrix(rnorm(nrow^2), nrow, nrow)
matB <- matrix(rnorm(nrow^2), nrow, nrow)

# create logical matrix indicating if signs are equal
logmat <- sign(matA) == sign(matB)
# count how many are equal