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.
1.4m articles
1.4m replys
5 comments
57.0k users