[R] "missings=function(x) x[x==998|x==999]<-NA" doesn't work...
Doreen Mueller
Doreen.Mueller at dza.de
Thu Sep 18 16:13:55 CEST 2014
Hi!
I want to have a function that assigns NAs to certain values of my
variable "var" in the dataset "d". This doesn't work:
> missings=function(x) x[x==998|x==999]<-NA
> missings(d$var)
> table(d$var, useNA="always")
0 1 999 <NA>
220 752 321 5264
I don't get any error messages, but "d$var" remains unchanged. The
function:
> missings=function(x) x[x==90|x==99]<<-NA
doesn't work either, and I read that "<<-" is "dangerous" anyway?
It is important for me to work with variable names (and therefore with
functions instead loops) because the number and order of variables in my
dataset changes regularly.
Thank you,
Doreen
[[alternative HTML version deleted]]
More information about the R-help
mailing list