View source: R/format_invalue.R
| finput | R Documentation |
Creates an invalue format that converts formatted labels back to values.
This is similar to 'SAS' PROC FORMAT with INVALUE statement.
The invalue is automatically stored in the global format library if name
is provided.
finput(..., name = NULL, target_type = "numeric", missing_value = NA)
... |
Named arguments defining label-value mappings (reverse of |
name |
Character. Optional name for the invalue format. If provided, the invalue is automatically registered in the global format library. |
target_type |
Character. Type to convert to: |
missing_value |
Value to use for missing inputs (default: |
An object of class "ks_invalue" containing the invalue definition.
The object is also stored in the format library if name is given.
# Convert text labels to numeric codes
finput(
"Male" = 1,
"Female" = 2,
name = "sex_inv"
)
# Apply using finputn (numeric invalue by name)
finputn(c("Male", "Female", "Unknown"), "sex_inv")
# [1] 1 2 NA
fclear()
# From a named vector
finput(c(Male = 1, Female = 2), name = "sex_inv2")
finputn(c("Male", "Female"), "sex_inv2")
# [1] 1 2
fclear()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.