# make toy demographic (age, gender, raceth) data set
set.seed(555)
df <- make_demo_data(n = 1000)
# let's add variable VALUE labels for variable "raceth"
df <- add_val_labs(df,
vars = "raceth", vals = c(1:7),
labs = c("White", "Black", "Latino", "Asian", "AIAN", "Multi", "Other"),
max.unique.vals = 50
)
# let's add variable VALUE labels for variable "gender"
df <- add_val1(
data = df, gender, vals = c(0, 1, 2),
labs = c("M", "F", "O"), max.unique.vals = 50
)
# let's add variable NAME labels
df <- add_name_labs(df, name.labs = c(
"age" = "Age in years",
"raceth" = "raceth category",
"gender" = "gender assigned at birth"
))
# let's add a frame label
df <- add_frame_lab(df, frame.lab = "This is a fictional data set that includes
demographic variables. It is generated by
labelr::make_demo_data")
# show attributes
attributes(df)
# re-arrange and show attributes
df2 <- clean_data_atts(df)
attributes(df2)
# confirm that attributes from df are all present in df2
all(attributes(df) %in% attributes(df2)) # TRUE
Run the code above in your browser using DataLab