Add "map" attributes from df2 to df1.
add_attr(df1, df2)
Data frame to receive attributes.
Data frame to give attributes.
Data frame.
df1 <- df2 <- data.frame(cars = 1:3)
attr(df2$cars, "map") <- data.frame(levels = 1:3,
labels = c("Volvo", "Saab", "Opel"))
df1 <- add_attr(df1, df2)
df1$cars
#> [1] 1 2 3
#> attr(,"map")
#> levels labels
#> 1 1 Volvo
#> 2 2 Saab
#> 3 3 Opel