I've imported a black and white pnm file with read.pnm(x). I have then used getChannels(x) to create matrix y. In this matrix, the black pixels are '0's, and the white pixels are '1's. I want the inverse of this, the black to be '1' and the white to be '0'. I know I can use a nested for loop to go through and correct all the values manually with val = 1 - val , but I was wondering if there is an easier way, or a function in R to 'reverse' or 'invert' a binary matrix like this without a nested for loop.
2.1m questions
2.1m answers
60 comments
57.0k users