| fmap | R Documentation |
Convenience helper for building data-driven formats with fnew.
Returns a named vector (or list) with class "ks_fmap" that signals
fnew() to use the natural direction: names are input keys,
values are output labels/objects — regardless of the format type.
fmap(keys, values)
keys |
Character vector of input keys (lookup values). |
values |
Vector of output labels or objects (character, numeric, Date, POSIXct, logical, etc.). |
Without fmap(), fnew() reverses named vectors for character
and numeric types (the factor() convention c(Label = "Code")).
Wrapping your data in fmap() suppresses this reversal, so
fmap(keys, values) works identically for character, numeric, Date,
POSIXct, and logical formats.
A named vector (or list, for non-atomic values) with class
c("ks_fmap", <original class>). Names are keys, values are
values.
fnew for format creation.
# Character lookup: keys -> labels
fmap(c("M", "F"), c("Male", "Female")) |> fnew(name = "sex")
fput(c("M", "F"), "sex")
fclear()
# Date lookup from a data frame
ids <- c("SUBJ-001", "SUBJ-002")
dates <- as.Date(c("2023-03-09", "2024-08-13"))
fmap(ids, dates) |> fnew(type = "Date", name = "icdtn")
fput("SUBJ-001", "icdtn")
fclear()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.