How can I replace values ββin one line with NA in R?
I have a text file:
df=read.table("E:\\value.txt", sep="\t")
df
k jh fg
1 208 0.15 0.17
2 304 0.00 0.08
Now I want to replace unnecessary values ββin k
withNA
df$k[df$k >= 500 ]=NA
No problem with this, but I would like to replace all matching values ββ(on the same line in jh and fg
) with NA
!)
source to share
It's hard to imagine that this hasn't been illustrated in some previous answer (but I've been looking):
is.na(df1[df1$k >300, ] ) <- TRUE
The fact that this is acceptable code for a dataframe object "[.data.frame"
tells me that it might also work for a more complex case where the column classes were more varied. There are special methods is.na<-
for certain classes:
> methods(`is.na<-`)
[1] is.na<-.default is.na<-.discrete is.na<-.factor
source to share