I am trying to replace all * values in my dataset with NA but I get errors.
Here is what I do:
strt = as.POSIXct("2021-01-08")
end = as.POSIXct("2021-01-12")
time = seq.POSIXt(strt, end, by = "day")
x = c(1,2,3,'*','*')
y = c('*',2,3,4,5)
df = data.frame(time, x, y)
df[df == '*'] = NA #This doesn't work
df[df[-1] == '*'] = NA #Same as above
df[df[,-1] == '*'] = NA #Same as above
There is a problem with POSIXct variable (time). The error is:
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
I tried disregarding time variable by writing df[df[-1] == '*'] but then I get another error:
Error in [<-.data.frame
(*tmp*
, df[, -1] == "", value = NA) :
unsupported matrix index in replacement*
So now I'm stuck. Does anyone know what's the problem here and why R can't run consistently with all types of variables?!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…