Skip to content

Feature suggestion: most() and assert_count_true() #539

@billdenney

Description

@billdenney

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions