The function, with the arguments x and y, should take a vector x and set all values greater than or equal to y to missing value (NA). Example: my_function(x = c(1,2,3,4,5,6), y = y)
should return the vector: [1] 1 2 3 NA NA NA
.
CodePudding user response:
You can use is.na<-
to replace values with NA.
my_function <- \(x, y) `is.na<-`(x, x >= y)
my_function(c(1,2,3,4,5,6), 4)
#[1] 1 2 3 NA NA NA