I have a matrix in which I want to replace some values if they meet a condition.

```
#example matrix
data <- c(1:10, 1:3, 1:4, 1:10, 1:3, 1:10)
mymatrix <- matrix(data, nrow = 10, ncol = 4)
```

I want to replace the matrix value with 0 if it is the same as the value to the left (by row). Example:

so mymatrix[3,2]==mymatrix[3,1], thus I I would like to replace mymatrix[3,2] with 0. I want to check all values in the matrix by row for this.

I am looking for something like.. if(mymatrix[x,y]==mymatrix[x,y-1]) { 0}, but cannot find something that works