Sorry, there was a stupid cut & paste mistake (missing parentheses in return statement...) ConvertMissingToNA <- function(values) { values[values == -9999 | values == -999999] <- NA return(values) } Peter