add_lab_atts {labelr} | R Documentation |
Add labelr Attributes from a list to a Data Frame
Description
add_lab_atts
allows one to apply a list of labelr label attribute meta-data
(created by get_all_lab_atts
) to a data.frame.
Usage
add_lab_atts(
data,
lab.atts.list,
strip.first = FALSE,
num.convert = FALSE,
clean = TRUE
)
Arguments
data |
a data.frame object. |
lab.atts.list |
a list previously created using |
strip.first |
FALSE if you do not wish to strip the data.frame of all label attribute information it may already have (this information may still be overwritten, depending on what is in the lab.atts.list list). |
num.convert |
attempt to convert to numeric any data.frame variables where this can be done without producing new NA values. |
clean |
after adding label attributes, put them into a neat, logical order and drop any attributes that describe variables (columns) not present in the data.frame to which they have been added. |
Details
See get_all_lab_atts
.
add_lab_atts
allows one to add or restore label attributes from a free-
standing list (created by get_all_lab_atts
) to a data.frame.
Value
a data.frame object with label attribute information (re-) attached (if it exists in the specified lab.atts.list).
Examples
# make toy demographic (gender, raceth, etc.) data set
set.seed(555)
df <- make_demo_data(n = 1000) # another labelr:: function
# let's add variable VALUE labels for variable "raceth"
df <- add_val_labs(df,
vars = "raceth", vals = c(1:7),
labs = c("White", "Black", "Hispanic", "Asian", "AIAN", "Multi", "Other"),
max.unique.vals = 50
)
get_val_labs(df, "raceth") # it's here
zlab.df <- get_all_lab_atts(df) # back up labelr attributes for df
df <- strip_labs(df) # this removes labs from df
get_val_labs(df, "raceth") # it's gone
check_any_lab_atts(df) # FALSE (means "no labs here")
df <- add_lab_atts(df, zlab.df) # restore them