I know that certain column in dataframe have limited known number of possible values (missing values are allowed). I wanted to validate that using validate library. I got unexpected error:
library(validate)
df <- data.frame(x = c(1:3, NA))
v <- validator(x %in% c(1, 2, 3, NA))
confront(df, v)
What is wrong with this code?
Following code works fine.
df$x %in% c(1, 2, 3, NA)
It doesn't like the NA.
Even v is error-some already.
You can however do something like v <- validator(x %in% c(1,2,3) | is.na(x))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With