Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R validate library

Tags:

validation

r

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)
like image 884
Tomek Tarczynski Avatar asked Dec 30 '25 19:12

Tomek Tarczynski


1 Answers

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))

like image 130
RolandASc Avatar answered Jan 02 '26 07:01

RolandASc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!