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]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.