# create a data set
df <- mtcars
# variable names and their labels
names_labs_vec <- c(
"mpg" = "Miles/(US) gallon",
"cyl" = "Number of cylinders",
"disp" = "Displacement (cu.in.)",
"hp" = "Gross horsepower",
"drat" = "Rear axle ratio",
"wt" = "Weight (1000 lbs)",
"qsec" = "1/4 mile time",
"vs" = "Engine (0 = V-shaped, 1 = straight)",
"am" = "Transmission (0 = automatic, 1 = manual)",
"gear" = "Number of forward gears",
"carb" = "Number of carburetors"
)
# assign variable labels
df <- add_name_labs(df,
vars = names(names_labs_vec),
labs = names_labs_vec
)
# see what we have
get_name_labs(df)
# drop the name label for var/col "am"
df <- drop_name_labs(df, "am")
# see what this did to the name label for "am"
get_name_labs(df)
# now, drop all of the name labels
df <- drop_name_labs(df)
get_name_labs(df) # they're gone
Run the code above in your browser using DataLab