# convert haven vector labels to labelr value labels
library(haven)
library(tibble)
x1 <- labelled(1:8, c(good = 1, bad = 5))
x2 <- labelled(1:8, c(good = 1, mediocre = 4, bad = 5, horrible = 8))
# make this a tibble
hdf <- tibble::tibble(x1, x2)
hdf # how it looks
# convert value labels to labelr label values
hdf1 <- convert_labs(hdf)
# show select values of hdf1
head(hdf1)
# show that labelr labels are there for the using
head(use_val_labs(hdf1))
# filter hdf1 using x1's "bad" labelr value label (with flab())
head(flab(hdf1, x1 == "bad"), 3)
# filter hdf1 using x1's "good" value label (with flab())
head(flab(hdf1, x1 == "good"), 3)
# return select rows and columns with slab()
slab(hdf1, x2 %in% c("good", 2), x2)
slab(hdf1, x2 %in% c("good", 2), x1)
Run the code above in your browser using DataLab