Description Usage Arguments Details Value Examples
A helper function to build df-specific search tools. These functions are typically used in conjunction with lapply to determine if they are present in a df.
1 | check.value(ids)
|
X |
Search term |
dat |
a lookup table data frame with both "id" and "field" columns |
field |
the search column name |
value |
the value to match |
exclude |
return the inverse logical value. |
unique_match |
If the combination of specified search terms return multiple fields this function will return TRUE by default if ANY match the supplied value. Specify unique_match = TRUE to require a single field to be identified before comparison. |
Important: since both the child function accepts multiple arguments (...) when it is built with multiple ids, you must explicitly refer to additional variables my name (dat, field, value). Without them the function returns NA even with valid queries.
logical
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | df <- data.frame(Patient.ID = c("p1", "p1", "p2", "p2", "p3"),
Visit = c(1, 2, 1, 2, NA),
Test.Result= c("neg","pos","neg", NA, "pos"),
stringsAsFactors = F)
check_value_by_patient_id <- check.value("Patient.ID")
check_value_by_patient_id("p1", dat = df, field = "Test.Result", value = "pos")
# TRUE
check_value_by_patient_id("p1", df, "Test.Result", "pos")
# returns NA inappropriately
check_value_by_patient_id("p2", dat = df, field = "Test.Result", value = "pos")
# FALSE
check_by_id_and_visit <- check.value(c("Patient.ID", "Visit"))
check_by_id_and_visit("p2", 1, dat = df, field = "Test.Result", value = "pos")
# FALSE
check_by_id_and_visit("p3", NA, dat = df, field = "Test.Result", value = "pos")
# NA
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.