Returns a sorted (descending) frequency tbl
tabsort(.data, ..., prop = TRUE, na_omit = TRUE, sort = TRUE) ntbl(.data, ...)
.data | Data |
---|---|
... | Unquoted column names of variables to include in table. Default is to use all columns. |
prop | Logical indicating whether to include a proportion of total obs column. |
na_omit | Logical indicating whether to exclude missing. If all responses are missing, a missing value is used as the single category. |
sort | Logical indicating whether to sort the returned object. |
Frequency tbl
## generate example data x <- sample(letters[1:4], 200, replace = TRUE) y <- sample(letters[5:8], 200, replace = TRUE) ## count and sort frequencies for each vector tabsort(x)#> # A tibble: 4 x 3 #> x n prop #> <chr> <int> <dbl> #> 1 a 52 0.26 #> 2 c 52 0.26 #> 3 b 48 0.24 #> 4 d 48 0.24tabsort(y)#> # A tibble: 4 x 3 #> x n prop #> <chr> <int> <dbl> #> 1 g 53 0.265 #> 2 f 52 0.26 #> 3 e 48 0.24 #> 4 h 47 0.235## combine x and y into data frame dat <- data.frame(x, y) ## select columns and create freq table tabsort(dat, x)#> # A tibble: 4 x 3 #> x n prop #> <chr> <int> <dbl> #> 1 a 52 0.26 #> 2 c 52 0.26 #> 3 b 48 0.24 #> 4 d 48 0.24tabsort(dat, x, y)#> # A tibble: 16 x 4 #> x y n prop #> <chr> <chr> <int> <dbl> #> 1 c g 18 0.09 #> 2 d g 15 0.075 #> 3 a h 15 0.075 #> 4 a e 14 0.07 #> 5 b e 14 0.07 #> 6 a f 14 0.07 #> 7 c f 14 0.07 #> 8 b f 12 0.06 #> 9 d f 12 0.06 #> 10 b g 11 0.055 #> # … with 6 more rows