[R] Convert values below threshold to 0 (different threshold/column)
smartpink111 at yahoo.com
Mon Feb 17 17:54:10 CET 2014
May be this helps:
mat1 <- matrix(sample(120,40*13,replace=TRUE),ncol=13)
th1 <- sample(30,13,replace=TRUE)
indx <- mapply("<",as.data.frame(mat1),th1)
indx1 <- !mapply(findInterval,as.data.frame(mat1),th1)
indx2 <- t((t(mat1)-th1) <0)
mat1[indx1] <- NA #or 0
I am a beginner and have a 872x13 double matrix. For my calculations
I need to replace all values below specific thresholds with 0 or NA. My
problem is that I have for each column a different threshold.
Thus far, I tried to substract the threshold and then replace a
values below 0 with NA and calculated the means using colMeans(M, na.rm =
TRUE). However, for my purpose I don't want to substract. I am sure
there is an easy function which can just define a specific threshold for
I already generated a threshold matrix.
Thanks for your help.
More information about the R-help