Muhammad Aaqib Shamim
Muhammad Aaqib Shamim

Reputation: 47

Can we change the name of values of a categorical variable in the tbl_summary function of the gtsummary package in R?

Continuing from the title, can I change the values of education from '1,2,3,4' to 'primary school, high school, university etc.' ?

We can change in the output, but I wished to know if it's possible in the code. I have tried reading the documentation of gtsummary but did not find the answer.

enter image description here

Upvotes: 0

Views: 664

Answers (1)

Marco
Marco

Reputation: 2797

As the comment suggests, it's about the levels of a factor variable.

data(mtcars)

as_tibble(mtcars)

mtcars$cyl <- as.factor(mtcars$cyl)
levels(mtcars$cyl) <- c("low", "middle", "high")

library(gtsummary)
tbl_summary(mtcars)

enter image description here

Upvotes: 0

Related Questions