问题
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