Description Usage Arguments 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 | lookup.values(id)
|
id |
Used during function creation to customize which df columns are used for search. This can be a vector. |
X |
Search term, this can be a vector |
dat |
a data frame with both "id" and "field" columns |
field |
the search column name |
value from field corresponding to search terms. This function can select multiple field values that are collapsed with separator to conserve dimensionality
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)
lookup_by_patientid <- lookup.values("Patient.ID")
lookup_by_patientid("patient2", df, "Test.Result")
# "negative"
lookup_by_patientid("patient1", df, "Test.Result")
# "negative; positive"
lookup_by_id_and_visit <- lookup.values(id = c("Patient.ID", "Visit"))
lookup_by_id_and_visit(X = c("patient1", 2), dat = df, field = "Test.Result")
# "positive"
# get results for all patients on their first visit
p <- strsplit(paste(unique(df$Patient.ID),1, sep = ";"), split = ";")
unlist(lapply(p, lookup_by_id_and_visit, dat = df, field = "Test.Result"))
# "negative" "negative"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.