I have created a matrix of binary digits from reading in a pgm file using the R package pixmap but I am trying to inverse the binary digits (making all 0s become 1s and all 1s become 0s) and outputting the matrix again. Is there an efficient way of doing this?
matrix <- +(!matrix)
The ! coerces it into a logical matrix and switches the 0s and 1s to TRUE and FALSE. The + coerces it back to 0s and 1s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With