I have a matrix similar to this:
m <- matrix(rnorm(100), 100, 50)
and I'd like to change all the values row by row, so that any value above its row (standard deviation) *2 will become 1, otherwise 0 (basically a threshold).
I tried something like this:
cutoff <- function(x){
x[x < 2*sd(x)] <- 0
x[x > 2*sd(x)] <- 1
return(x)
}
mT <- apply(m, 1, cutoff)
but it's giving me something different. Any help would be very appreciated.