EVOLUTION-MANAGER
Edit File: adorn_ns.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Add underlying Ns to a tabyl displaying percentages.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for adorn_ns {janitor}"><tr><td>adorn_ns {janitor}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Add underlying Ns to a tabyl displaying percentages.</h2> <h3>Description</h3> <p>This function adds back the underlying Ns to a <code>tabyl</code> whose percentages were calculated using <code>adorn_percentages()</code>, to display the Ns and percentages together. You can also call it on a non-tabyl data.frame to which you wish to append Ns. </p> <h3>Usage</h3> <pre> adorn_ns(dat, position = "rear", ns = attr(dat, "core"), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>dat</code></td> <td> <p>a data.frame of class <code>tabyl</code> that has had <code>adorn_percentages</code> and/or <code>adorn_pct_formatting</code> called on it. If given a list of data.frames, this function will apply itself to each data.frame in the list (designed for 3-way <code>tabyl</code> lists).</p> </td></tr> <tr valign="top"><td><code>position</code></td> <td> <p>should the N go in the front, or in the rear, of the percentage?</p> </td></tr> <tr valign="top"><td><code>ns</code></td> <td> <p>the Ns to append. The default is the "core" attribute of the input tabyl <code>dat</code>, where the original Ns of a two-way <code>tabyl</code> are stored. However, if you need to modify the numbers, e.g., to format <code>4000</code> as <code>4,000</code> or <code>4k</code>, you can do that separately and supply the formatted result here.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>columns to adorn. This takes a tidyselect specification. By default, all columns are adorned except for the first column and columns not of class <code>numeric</code>, but this allows you to manually specify which columns should be adorned, for use on a data.frame that does not result from a call to <code>tabyl</code>.</p> </td></tr> </table> <h3>Value</h3> <p>a data.frame with Ns appended </p> <h3>Examples</h3> <pre> mtcars %>% tabyl(am, cyl) %>% adorn_percentages("col") %>% adorn_pct_formatting() %>% adorn_ns(position = "front") # Control the columns to be adorned with the ... variable selection argument # If using only the ... argument, you can use empty commas as shorthand # to supply the default values to the preceding arguments: cases <- data.frame( region = c("East", "West"), year = 2015, recovered = c(125, 87), died = c(13, 12) ) cases %>% adorn_percentages("col",,recovered:died) %>% adorn_pct_formatting(,,,recovered:died) %>% adorn_ns(,,recovered:died) </pre> <hr /><div style="text-align: center;">[Package <em>janitor</em> version 2.1.0 <a href="00Index.html">Index</a>]</div> </body></html>