dictionary | R Documentation |
Extracts a specified attribute from each column of a data frame and returns a dictionary as a data frame mapping variable names to their corresponding attribute values.
dictionary(df, attribute = "label", na.rm = TRUE)
df |
A data frame whose columns may have attached attributes. |
attribute |
A character string specifying the name of the attribute to extract from each column (e.g., "label"). |
na.rm |
Logical; if |
The function iterates over each column in the input data frame df
and retrieves the specified attribute using attr()
. If the attribute is not found for a column, NA
is returned as its description. The resulting data frame acts as a dictionary for the variables, which is particularly useful for documenting datasets during exploratory data analysis.
A data frame with two columns:
The names of the variables in df
.
The extracted attribute values from each variable.
E. F. Haghish
# Example: Generate a dictionary of variable labels using the USJudgeRatings dataset.
# This dataset contains ratings on various performance measures for U.S. federal judges.
data("USJudgeRatings")
# Assume that the dataset's variables have been annotated with "label" attributes.
# which is the default label read by dictionary
attr(USJudgeRatings$CONT, "label") <- "Content Quality"
attr(USJudgeRatings$INTG, "label") <- "Integrity"
attr(USJudgeRatings$DMNR, "label") <- "Demeanor"
attr(USJudgeRatings$DILG, "label") <- "Diligence"
# Generate the dictionary of labels
dict <- dictionary(USJudgeRatings, "label")
print(dict)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.