Replace all values in a matrix <0.1 with 0

后端 未结 6 1244
执念已碎
执念已碎 2020-11-29 23:31

I have a matrix (2601 by 58) of particulate matter concentration estimates from an air quality model. Because real-life air quality monitors cannot measure below 0.1 ug/L,

6条回答
  •  醉话见心
    2020-11-30 00:11

    A data.frame solution:

    if(!require(plyr)){
        install.packages("plyr")}
    
    rm.neg<-colwise(function(x){
      return(ifelse(x < 0.1, 0, x))})
    
    rm.neg(data.frame(mat))
    

    PS: the code for rm.neg can be extracted and simplified so as not to need a call to plyr, which is used to create the colwise function.

提交回复
热议问题