I have a 5x4 matrix and I want to select all elements (to be set to 0) except those in rows 2 to 4 AND columns 2 to 3. Basically, all the elements along the "edges" of the matrix should be set to 0. Currently, my code is
mat[ -(2:4), -(2:3) ] <- 0
However, this (de)selects the elements in an OR fashion so instead, only the corners of the matrix are set to 0. How can I choose them in AND fashion?