This function is a wrapper around a very common data transformation that is done every time we make a frequency plot
Examples
library(tibble)
library(dplyr)
library(labelled)
library(haven)
# create the fake data
df <- tibble::tribble(
~x, ~y, ~z,
3, 2, 3,
4, 4, 2,
2, 6, 1,
1, 1, 4,
5, 4, 3,
6, 5, 6
)
df %>%
count(x) %>%
mutate(pct = prop.table(n)) %>%
pct_conv()
#> # A tibble: 6 × 4
#> x n pct pct_lab
#> <dbl> <int> <dbl> <chr>
#> 1 1 1 16.7 16.7%
#> 2 2 1 16.7 16.7%
#> 3 3 1 16.7 16.7%
#> 4 4 1 16.7 16.7%
#> 5 5 1 16.7 16.7%
#> 6 6 1 16.7 16.7%