countpct.Rd
Provided two columns, create a new column representing a number and percentage
countpct(.data, n, perc, name = "N", accuracy = 0.01, remove = TRUE)
.data | A tbl. |
---|---|
n | Column of values. |
perc | Column of percentages (as decimals). |
name | Name of new column. |
accuracy | Number to round to, NULL for automatic guess. |
remove | If TRUE, remove input columns from output data frame. |
iris %>% dplyr::group_by(Species) %>% dplyr::summarise(n = dplyr::n()) %>% dplyr::ungroup() %>% dplyr::mutate(freq = prop.table(n)) %>% countpct(n, freq)#>#> # A tibble: 3 x 2 #> Species N #> <fct> <chr> #> 1 setosa 50 (33.33%) #> 2 versicolor 50 (33.33%) #> 3 virginica 50 (33.33%)