I want to check if x is NULL/NA/NAN and if it is, then carry out the function. I also want to carry out the function if x is not between a min and a max number.
If I do:
#Checks if blank
isnothing <- function(x) {
any(is.null(x)) || any(is.na(x)) || any(is.nan(x))
}
x <- as.numeric(NULL)
min <- 25
max <- 45
#Actual function
if (isnothing(x) | !between(x,min,max)) {
#Do something
}
I get the dreaded "argument is of length zero in if statement" error in R
I also tried:
x <- as.numeric(NULL)
min <- 25
max <- 45
if (isnothing(x) |(!isnothing(x) & !between(x,min,max))) {
#Do something
}
This still doesn't work
Aucun commentaire:
Enregistrer un commentaire