R: Convert a data.frame of counts to percentages.

adorn_percentages {janitor} | R Documentation

## Convert a data.frame of counts to percentages.

### Description

This function excludes the first column of the input data.frame, assuming that it contains a descriptive variable. If the input data.frame is not a `tabyl`, it will convert to one in order to preserve the underlying values in the `core` attribute.

### Usage

    adorn_percentages(dat, denominator = "row", na.rm = TRUE)

### Arguments

`dat` | a `tabyl` or other data.frame with a tabyl-like layout. If given a list of data.frames, this function will apply itself to each data.frame in the list (designed for 3-way `tabyl` lists).
`denominator` | the direction to use for calculating percentages. One of "row", "col", or "all".
`na.rm` | should missing values (including NaN) be omitted from the calculations?

### Value

Returns a data.frame of percentages, expressed as numeric values between 0 and 1.

### Examples

    mtcars %>%
      tabyl(am, cyl) %>%
      adorn_percentages("col")

    # calculates correctly even with totals column and/or row:
    mtcars %>%
      tabyl(am, cyl) %>%
      adorn_totals("row") %>%
      adorn_percentages()

[Package janitor version 1.0.0 Index]