0

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.

tobinz
  • 117
  • 1
  • 9

1 Answers1

0

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)
hello_friend
  • 5,682
  • 1
  • 11
  • 15