'R validate: how to check if individual values (not the entire column) are numbers?

I am running some checks on my data frame using the R validate package

I want to check if values in my column Protocol Number are actually numbers. When I write the expression using is.numeric I get the following output:

enter image description here

The documentation linked above says "We see that each rule checks a single item, namely one column of data" But this is not what I want. I don't want to check the entire column of data but each individual value.

As a result, when I call violating() I get an error to show rows that don't hold numbers

Error in violating(assaydat, out) : Not all rules have record-wise output

The column Protocol Number is actually a character vector, and some possible values (among many) are "1", "2", "3" or a comment like "Not Done" or "Pending". I want to flag each row in the data frame if there is a comment and not a number.

How do I do this correctly?



Solution 1:[1]

You can use:

grepl("^[0-9]+$", `Protocol Number`)

It will return TRUE is the column contains only digits, and FALSE otherwise.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2332849