-
Notifications
You must be signed in to change notification settings - Fork 132
Description
I sometimes get dirty data that has multiple values that I need to choose one from. In a recent example, I received a dataset where an individual had multiple values for their sex (both male and female when they definitely did not undergo gender reassignment between the measurements).
To work with these types of issues, I think that two different types of functions can help:
most(x) is a companion to any() and all() from base R. It takes in a vector, x, and returns true if more than half of the values are isTRUE(x).
assert_count_true(x, n) takes in a logical vector x and an expected count that should be isTRUE(x), n. If sum(isTRUE(x)) == n, then it returns x. If a different number are TRUE, then it returns an error indicating the mismatch in count.