v1 <- c(4, 3, 8, 6, 9, 5, NA, 0, 7, 4, 3, 7)
# Format count and percent
fmt_cnt_pct(v1)
# Output
# [1] "4 ( 36.4%)" "3 ( 27.3%)" "8 ( 72.7%)" "6 ( 54.5%)"
# [5] "9 ( 81.8%)" "5 ( 45.5%)" NA "0 ( 0.0%)"
# [9] "7 ( 63.6%)" "4 ( 36.4%)" "3 ( 27.3%)" "7 ( 63.6%)"
# Custom values for NA and zero
fmt_cnt_pct(v1, na = "N/A", zero = "0 (-)")
# Custom NA and zero output
# [1] "4 ( 36.4%)" "3 ( 27.3%)" "8 ( 72.7%)" "6 ( 54.5%)"
# [5] "9 ( 81.8%)" "5 ( 45.5%)" "N/A" "0 (-)"
# [9] "7 ( 63.6%)" "4 ( 36.4%)" "3 ( 27.3%)" "7 ( 63.6%)"
Run the code above in your browser using DataLab