# NOT RUN {
data(efc)
# create subset - drops label attributes
efc.sub <- subset(efc, subset = e16sex == 1, select = c(4:8))
str(efc.sub)
# copy back attributes from original dataframe
efc.sub <- copy_labels(efc.sub, efc)
str(efc.sub)
# remove all labels
efc.sub <- copy_labels(efc.sub)
str(efc.sub)
# create subset - drops label attributes
efc.sub <- subset(efc, subset = e16sex == 1, select = c(4:8))
if (require("dplyr")) {
# create subset with dplyr's select - attributes are preserved
efc.sub2 <- select(efc, c160age, e42dep, neg_c_7, c82cop1, c84cop3)
# copy labels from those columns that are available
copy_labels(efc.sub, efc.sub2) %>% str()
}
# copy labels from only some columns
str(copy_labels(efc.sub, efc, e42dep))
str(copy_labels(efc.sub, efc, -e17age))
# }
Run the code above in your browser using DataLab