Replace all values in a matrix <0.1 with 0

后端 未结 6 1227
执念已碎
执念已碎 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条回答
  •  Happy的楠姐
    2020-11-30 00:21

    Just to provide an (in my opinion) interesting alternative:

    If you need to clamp the values so they are never smaller than a value, you could use pmax:

    set.seed(42)
    m <- matrix(rnorm(100),10)
    
    m <- pmax(m, 0) # clamp negative values to 0
    

    ...This doesn't quite work in your case though since you want values < 0.1 to become 0.

提交回复
热议问题