# assign mtcars to df
df <- mtcars
# assign the rownames to a column
id <- rownames(df)
df <- cbind(id, df)
# split the data.frame into two
df_a <- df[c("id", "am")]
df_b <- df[c("id", "mpg")]
# add value labels to df_a$am
df_a <- add_val_labs(
data = df_a,
vars = "am",
vals = c(0, 1),
labs = c("automatic", "manual")
)
# add numerical range value labels to df_b$mpg
df_b <- add_quant1(df_b, mpg, qtiles = 4)
# now, safely merge them
df_m <- smerge(df_a, df_b)
head(df_m)
get_val_labs(df_m)
Run the code above in your browser using DataLab