<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content="Summary statistics for a single numeric variable, possibly separated by the levels of a factor variable or variables. This function is very similar to summary for a numeric variable."><title>Summary statistics for a numeric variable. — Summarize • FSA</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.2.2/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.2.2/bootstrap.bundle.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Summary statistics for a numeric variable. — Summarize"><meta property="og:description" content="Summary statistics for a single numeric variable, possibly separated by the levels of a factor variable or variables. This function is very similar to summary for a numeric variable."><meta property="og:image" content="https://fishr-core-team.github.io/FSA/logo.png"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>
    

    <nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
    
    <a class="navbar-brand me-2" href="../index.html">FSA</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Released version">0.9.5</small>

    
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item">
  <a class="nav-link" href="../reference/index.html">Reference</a>
</li>
      </ul><form class="form-inline my-2 my-lg-0" role="search">
        <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>

      <ul class="navbar-nav"><li class="nav-item">
  <a class="nav-link" href="../news/index.html">
    <span class="fa fa-newspaper"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="nav-link" href="../index.html">
    <span class="fa fa-home fa"></span>
     
  </a>
</li>
<li class="nav-item">
  <a class="external-link nav-link" href="https://github.com/fishR-Core-Team/FSA">
    <span class="fa fa-github fa"></span>
     
  </a>
</li>
      </ul></div>

    
  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.png" class="logo" alt=""><h1>Summary statistics for a numeric variable.</h1>
      <small class="dont-index">Source: <a href="https://github.com/fishR-Core-Team/FSA/blob/HEAD/R/Summarize.R" class="external-link"><code>R/Summarize.R</code></a></small>
      <div class="d-none name"><code>Summarize.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Summary statistics for a single numeric variable, possibly separated by the levels of a factor variable or variables. This function is very similar to <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></code> for a numeric variable.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">object</span>, <span class="va">...</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># S3 method for default</span></span>
<span><span class="fu">Summarize</span><span class="op">(</span></span>
<span>  <span class="va">object</span>,</span>
<span>  digits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"digits"</span><span class="op">)</span>,</span>
<span>  na.rm <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  exclude <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  nvalid <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"different"</span>, <span class="st">"always"</span>, <span class="st">"never"</span><span class="op">)</span>,</span>
<span>  percZero <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"different"</span>, <span class="st">"always"</span>, <span class="st">"never"</span><span class="op">)</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># S3 method for formula</span></span>
<span><span class="fu">Summarize</span><span class="op">(</span></span>
<span>  <span class="va">object</span>,</span>
<span>  data <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  digits <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"digits"</span><span class="op">)</span>,</span>
<span>  na.rm <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  exclude <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  nvalid <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"different"</span>, <span class="st">"always"</span>, <span class="st">"never"</span><span class="op">)</span>,</span>
<span>  percZero <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"different"</span>, <span class="st">"always"</span>, <span class="st">"never"</span><span class="op">)</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
    <dl><dt>object</dt>
<dd><p>A vector of numeric data.</p></dd>


<dt>...</dt>
<dd><p>Not implemented.</p></dd>


<dt>digits</dt>
<dd><p>A single numeric that indicates the number of decimals to round the numeric summaries.</p></dd>


<dt>na.rm</dt>
<dd><p>A logical that indicates whether numeric missing values (<code>NA</code>) should be removed (<code>=TRUE</code>, default) or not.</p></dd>


<dt>exclude</dt>
<dd><p>A string that contains the level that should be excluded from a factor variable.</p></dd>


<dt>nvalid</dt>
<dd><p>A string that indicates how the “validn” result will be handled. If <code>"always"</code> then “validn” will always be shown and if <code>"never"</code> then “validn” will never be shown. However, if <code>"different"</code> (DEFAULT), then “validn” will only be shown if it differs from “n” (or if at least one group differs from “n” when summarized by multiple groups).</p></dd>


<dt>percZero</dt>
<dd><p>A string that indicates how the “percZero” result will be handled. If <code>"always"</code> then “percZero” will always be shown and if <code>"never"</code> then “percZero” will never be shown. However, if <code>"different"</code> (DEFAULT), then “percZero” will only be shown if it is greater than zero (or if at least one group is greater than zero when summarized by multiple groups).</p></dd>


<dt>data</dt>
<dd><p>A data.frame that contains the variables in <code>formula</code>.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    

<p>A named vector or data frame (when a quantitative variable is separated by one or two factor variables) of summary statistics for numeric data.</p>
    </div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p>This function is primarily used with formulas of the following types (where <code>quant</code> and <code>factor</code> generically represent quantitative/numeric and factor variables, respectively):</p><table class="table table"><tr><td>Formula</td><td>Description of Summary</td></tr><tr><td><code>~quant</code></td><td>Numerical summaries (see below) of <code>quant</code>.</td></tr><tr><td><code>quant~factor</code></td><td>Summaries of <code>quant</code> separated by levels in <code>factor</code>.</td></tr><tr><td><code>quant~factor1*factor2</code></td><td>Summaries of <code>quant</code> separated by the combined levels in <code>factor1</code> and <code>factor2</code>.</td></tr></table><p>Numerical summaries include all results from <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></code> (min, Q1, mean, median, Q3, and max) and the sample size, valid sample size (sample size minus number of <code>NA</code>s), and standard deviation (i.e., <code>sd</code>). <code>NA</code> values are removed from the calculations with <code>na.rm=TRUE</code> (the DEFAULT). The number of digits in the returned results are controlled with <code>digits=</code>.</p>
    </div>
    <div class="section level2">
    <h2 id="note">Note<a class="anchor" aria-label="anchor" href="#note"></a></h2>
    <p>Students often need to examine basic statistics of a quantitative variable separated for different levels of a categorical variable. These results may be obtained with <code><a href="https://rdrr.io/r/base/tapply.html" class="external-link">tapply</a></code>, <code><a href="https://rdrr.io/r/base/by.html" class="external-link">by</a></code>, or <code><a href="https://rdrr.io/r/stats/aggregate.html" class="external-link">aggregate</a></code> (or with functions in other packages), but the use of these functions is not obvious to newbie students or return results in a format that is not obvious to newbie students. Thus, the formula method to <code>Summarize</code> allows newbie students to use a common notation (i.e., formula) to easily compute summary statistics for a quantitative variable separated by the levels of a factor.</p>
    </div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p>See <code><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></code> for related one dimensional functionality. See <code><a href="https://rdrr.io/r/base/tapply.html" class="external-link">tapply</a></code>, <code>summaryBy</code> in <span class="pkg">doBy</span>, <code><a href="https://rdrr.io/pkg/psych/man/describe.html" class="external-link">describe</a></code> in <span class="pkg">psych</span>, <code>describe</code> in <span class="pkg">prettyR</span>, and <code>basicStats</code> in <span class="pkg">fBasics</span> for similar “by” functionality.</p></div>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Derek H. Ogle, <a href="mailto:DerekOgle51@gmail.com">DerekOgle51@gmail.com</a></p>
    </div>

    <div class="section level2">
    <h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co">## Create a data.frame of "data"</span></span></span>
<span class="r-in"><span><span class="va">n</span> <span class="op">&lt;-</span> <span class="fl">102</span></span></span>
<span class="r-in"><span><span class="va">d</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>y<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">0</span>,<span class="fl">0</span>,<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="cn">NA</span>,<span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html" class="external-link">runif</a></span><span class="op">(</span><span class="va">n</span><span class="op">-</span><span class="fl">5</span><span class="op">)</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                w<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fl">7</span><span class="op">:</span><span class="fl">9</span>,<span class="va">n</span>,replace<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                v<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fl">0</span><span class="op">:</span><span class="fl">2</span>,<span class="va">n</span>,replace<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                g1<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">factor</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"A"</span>,<span class="st">"B"</span>,<span class="st">"C"</span>,<span class="cn">NA</span><span class="op">)</span>,<span class="va">n</span>,replace<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                g2<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/factor.html" class="external-link">factor</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"male"</span>,<span class="st">"female"</span>,<span class="st">"UNKNOWN"</span><span class="op">)</span>,<span class="va">n</span>,replace<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                g3<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"a"</span>,<span class="st">"b"</span>,<span class="st">"c"</span>,<span class="st">"d"</span><span class="op">)</span>,<span class="va">n</span>,replace<span class="op">=</span><span class="cn">TRUE</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>                stringsAsFactors<span class="op">=</span><span class="cn">FALSE</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># typical output of summary() for a numeric variable</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/base/summary.html" class="external-link">summary</a></span><span class="op">(</span><span class="va">d</span><span class="op">$</span><span class="va">y</span><span class="op">)</span>   </span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  0.0000  0.2667  0.5156  0.5131  0.7794  0.9975       3 </span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># this function           </span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">d</span><span class="op">$</span><span class="va">y</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n   nvalid     mean       sd      min       Q1   median       Q3 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  102.000   99.000    0.513    0.314    0.000    0.267    0.516    0.779 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      max percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    0.998    2.020 </span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="op">~</span><span class="va">y</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n   nvalid     mean       sd      min       Q1   median       Q3 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  102.000   99.000    0.513    0.314    0.000    0.267    0.516    0.779 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      max percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    0.998    2.020 </span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="fl">1</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n   nvalid     mean       sd      min       Q1   median       Q3 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  102.000   99.000    0.513    0.314    0.000    0.267    0.516    0.779 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      max percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    0.998    2.020 </span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># note that nvalid is not shown if there are no NAs and</span></span></span>
<span class="r-in"><span><span class="co">#   percZero is not shown if there are no zeros</span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="op">~</span><span class="va">w</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>       n    mean      sd     min      Q1  median      Q3     max </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 102.000   7.804   0.809   7.000   7.000   8.000   8.000   9.000 </span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="op">~</span><span class="va">v</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n     mean       sd      min       Q1   median       Q3      max </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  102.000    0.980    0.856    0.000    0.000    1.000    2.000    2.000 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   37.255 </span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># note that the nvalid and percZero results can be forced to be shown</span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="op">~</span><span class="va">w</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span>,nvalid<span class="op">=</span><span class="st">"always"</span>,percZero<span class="op">=</span><span class="st">"always"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n   nvalid     mean       sd      min       Q1   median       Q3 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  102.000  102.000    7.804    0.809    7.000    7.000    8.000    8.000 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      max percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>    9.000    0.000 </span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Numeric vector by levels of a factor variable</span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">g1</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   g1  n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  A 21     21 0.513 0.337 0.000 0.254  0.535 0.854 0.974    4.762</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  B 27     25 0.530 0.323 0.000 0.259  0.528 0.808 0.963    4.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  C 27     26 0.516 0.286 0.023 0.302  0.441 0.754 0.998    0.000</span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">g2</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        g2  n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 UNKNOWN 35     35 0.538 0.284 0.000 0.376  0.516 0.766 0.988    2.857</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  female 37     34 0.519 0.336 0.000 0.240  0.521 0.838 0.998    2.941</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3    male 30     30 0.478 0.329 0.003 0.189  0.515 0.755 0.963    0.000</span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">g2</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span>,exclude<span class="op">=</span><span class="st">"UNKNOWN"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>       g2  n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 female 37     34 0.519 0.336 0.000 0.240  0.521 0.838 0.998    2.941</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2   male 30     30 0.478 0.329 0.003 0.189  0.515 0.755 0.963    0.000</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Numeric vector by levels of two factor variables</span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">g1</span><span class="op">+</span><span class="va">g2</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   g1      g2  n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  A UNKNOWN  6      6 0.542 0.342 0.124 0.323  0.467 0.843 0.953    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  B UNKNOWN 10     10 0.616 0.298 0.000 0.475  0.582 0.894 0.947   10.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  C UNKNOWN 11     11 0.481 0.273 0.027 0.359  0.416 0.651 0.988    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  A  female  9      9 0.540 0.364 0.000 0.274  0.666 0.854 0.974   11.111</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  B  female  8      6 0.537 0.330 0.099 0.295  0.572 0.756 0.958    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6  C  female  8      7 0.500 0.370 0.023 0.238  0.421 0.791 0.998    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 7  A    male  6      6 0.444 0.344 0.017 0.213  0.394 0.708 0.894    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 8  B    male  9      9 0.429 0.354 0.003 0.147  0.280 0.709 0.963    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 9  C    male  8      8 0.578 0.248 0.186 0.360  0.720 0.746 0.819    0.000</span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">g1</span><span class="op">+</span><span class="va">g2</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span>,exclude<span class="op">=</span><span class="st">"UNKNOWN"</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   g1     g2 n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1  A female 9      9 0.540 0.364 0.000 0.274  0.666 0.854 0.974   11.111</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2  B female 8      6 0.537 0.330 0.099 0.295  0.572 0.756 0.958    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3  C female 8      7 0.500 0.370 0.023 0.238  0.421 0.791 0.998    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 4  A   male 6      6 0.444 0.344 0.017 0.213  0.394 0.708 0.894    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 5  B   male 9      9 0.429 0.354 0.003 0.147  0.280 0.709 0.963    0.000</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 6  C   male 8      8 0.578 0.248 0.186 0.360  0.720 0.746 0.819    0.000</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## What happens if RHS of formula is not a factor</span></span></span>
<span class="r-in"><span><span class="fu">Summarize</span><span class="op">(</span><span class="va">y</span><span class="op">~</span><span class="va">w</span>,data<span class="op">=</span><span class="va">d</span>,digits<span class="op">=</span><span class="fl">3</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   w  n nvalid  mean    sd   min    Q1 median    Q3   max percZero</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 1 7 45     44 0.585 0.323 0.000 0.320  0.707 0.879 0.974    2.273</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 2 8 32     32 0.461 0.319 0.000 0.196  0.403 0.677 0.998    3.125</span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 3 9 25     23 0.448 0.271 0.003 0.295  0.421 0.635 0.953    0.000</span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co">## Summarizing multiple variables in a data.frame (must reduce to numerics)</span></span></span>
<span class="r-in"><span><span class="fu"><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">as.list</a></span><span class="op">(</span><span class="va">d</span><span class="op">[</span>,<span class="fl">1</span><span class="op">:</span><span class="fl">3</span><span class="op">]</span><span class="op">)</span>,<span class="va">Summarize</span>,digits<span class="op">=</span><span class="fl">4</span><span class="op">)</span></span></span>
<span class="r-out co"><span class="r-pr">#&gt;</span> $y</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n   nvalid     mean       sd      min       Q1   median       Q3 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 102.0000  99.0000   0.5131   0.3142   0.0000   0.2667   0.5156   0.7794 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>      max percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>   0.9975   2.0202 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> $w</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n     mean       sd      min       Q1   median       Q3      max </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 102.0000   7.8039   0.8089   7.0000   7.0000   8.0000   8.0000   9.0000 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> $v</span>
<span class="r-out co"><span class="r-pr">#&gt;</span>        n     mean       sd      min       Q1   median       Q3      max </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> 102.0000   0.9804   0.8557   0.0000   0.0000   1.0000   2.0000   2.0000 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> percZero </span>
<span class="r-out co"><span class="r-pr">#&gt;</span>  37.2549 </span>
<span class="r-out co"><span class="r-pr">#&gt;</span> </span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p></p><p>Developed by <a href="http://derekogle.com" class="external-link">Derek H. Ogle</a>, Jason C. Doll, A. Powell Wheeler, Alexis Dinno.</p>
</div>

<div class="pkgdown-footer-right">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

    </footer></div>

  

  

  </body></html>

