Skip to content
Prev 156216 / 398506 Next

Unexpected returned value from a function

Quoting "Hutchinson,David [PYR]" <David.Hutchinson at ec.gc.ca>:
the assignment itself evaluates to the assigned value, in this case NA;
that's what your function returns. Check this:
[1] 3
[1] 3
[1] NA
[1] NA

this way your function should work as intended:

ConvertMissingToNA <- function(values)
{
     values[ values == -9999 | values == -999999] <- NA
     return values
}

Peter