Reputation: 41
I have a dataset imported from a *.sav file. As I read this file with the haven package, their factors are in the "have labelled" class. I'm knitting a report in rmarkdown and want some summary tibbles to be displayed in a more fancier way with kable and kableextra.
The type of knitted chunk looks like this.
modelo %>%
group_by(AREA_RESIDENCIA) %>%
summarise(proportion = survey_mean(DBT))
The output once knitted looks like this.
## # A tibble: 2 x 3
## AREA_RESIDENCIA proportion proportion_se
## <dbl+lbl> <dbl> <dbl>
## 1 1 [Urban] 0.0299 0.00211
## 2 2 [Rural] 0.0137 0.00171
I like that the label is shown in the tibble. I wonder if there is a way of knitting this tibble to a kable or kable extra format and still display the value labels, I can't find how. Of course I'm not taking into account reformatting the values to its labels, I would like to keep the variables as haven labelled and knit them in a fancy or nice html table.
Upvotes: 2
Views: 579
Reputation: 41
I did find the solution to my problem a while ago. I just needed to use the sjlabelled package. With that package, using the as_character function, the solution for the initial question would look like this:
library(sjlabelled)
modelo %>%
group_by(as_character(AREA_RESIDENCIA)) %>%
summarise(proportion = survey_mean(DBT))
Upvotes: 2