I came up with a very simple function:
done <- function(x){
x[x>1] <- NA
}
To test it, I created a variable:
test <- 0:10
and execute
done(test)
But it outputs the original test data, not giving any NA
.
You haven't defined a return object:
done <- function(x){
x[x>1] <- NA
return(x)
}
test <- 0:10
done(test)
Another approach:
ifelse(test > 1, NA_integer_, test)