R: replace all values in a dataframe lower than a threshold with NA

邮差的信 提交于 2021-02-04 08:32:05

问题


I would like to replace all values in a dataframe lower than a given threshold minval with NA. What would be the most elegant way to do this?


回答1:


Try this:

 df[df<minval]=NA

df < minval creates a boolean matrix, which is used to select the values you want to replace with NA.



来源:https://stackoverflow.com/questions/26468385/r-replace-all-values-in-a-dataframe-lower-than-a-threshold-with-na

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!