<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Filter Top n Microorganisms — top_n_microorganisms • AMR (for R)</title><!-- favicons --><linkrel="icon"type="image/png"sizes="16x16"href="../favicon-16x16.png"><linkrel="icon"type="image/png"sizes="32x32"href="../favicon-32x32.png"><linkrel="apple-touch-icon"type="image/png"sizes="180x180"href="../apple-touch-icon.png"><linkrel="apple-touch-icon"type="image/png"sizes="120x120"href="../apple-touch-icon-120x120.png"><linkrel="apple-touch-icon"type="image/png"sizes="76x76"href="../apple-touch-icon-76x76.png"><linkrel="apple-touch-icon"type="image/png"sizes="60x60"href="../apple-touch-icon-60x60.png"><scriptsrc="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><linkhref="../deps/bootstrap-5.3.1/bootstrap.min.css"rel="stylesheet"><scriptsrc="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><linkhref="../deps/Lato-0.4.9/font.css"rel="stylesheet"><linkhref="../deps/Fira_Code-0.4.9/font.css"rel="stylesheet"><linkhref="../deps/font-awesome-6.5.2/css/all.min.css"rel="stylesheet"><linkhref="../deps/font-awesome-6.5.2/css/v4-shims.min.css"rel="stylesheet"><scriptsrc="../deps/headroom-0.11.0/headroom.min.js"></script><scriptsrc="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><scriptsrc="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><scriptsrc="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><scriptsrc="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><scriptsrc="../deps/search-1.0.0/fuse.min.js"></script><scriptsrc="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><scriptsrc="../pkgdown.js"></script><linkhref="../extra.css"rel="stylesheet"><scriptsrc="../extra.js"></script><metaproperty="og:title"content="Filter Top n Microorganisms — top_n_microorganisms"><metaname="description"content="This function filters a data set to include only the top n microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera."><metaproperty="og:description"content="This function filters a data set to include only the top n microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera."><metaproperty="og:image"content="https://msberends.github.io/AMR/logo.svg"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css"integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+"crossorigin="anonymous"><scriptdefersrc="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js"integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg"crossorigin="anonymous"></script><scriptdefersrc="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js"integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk"crossorigin="anonymous"onload="renderMathInElement(document.body);"></script></head><body>
<buttonclass="nav-link dropdown-toggle"type="button"id="dropdown-how-to"data-bs-toggle="dropdown"aria-expanded="false"aria-haspopup="true"><spanclass="fa fa-question-circle"></span> How to</button>
<ulclass="dropdown-menu"aria-labelledby="dropdown-how-to"><li><aclass="dropdown-item"href="../articles/AMR.html"><spanclass="fa fa-directions"></span> Conduct AMR Analysis</a></li>
<li><aclass="dropdown-item"href="../articles/datasets.html"><spanclass="fa fa-database"></span> Download Data Sets for Own Use</a></li>
<li><aclass="dropdown-item"href="../articles/AMR_with_tidymodels.html"><spanclass="fa fa-square-root-variable"></span> Use AMR for Predictive Modelling (tidymodels)</a></li>
<li><aclass="dropdown-item"href="../reference/AMR-options.html"><spanclass="fa fa-gear"></span> Set User- Or Team-specific Package Settings</a></li>
<li><aclass="dropdown-item"href="../articles/PCA.html"><spanclass="fa fa-compress"></span> Conduct Principal Component Analysis for AMR</a></li>
<p>This function filters a data set to include only the top <em>n</em> microorganisms based on a specified property, such as taxonomic family or genus. For example, it can filter a data set to the top 3 species, or to any species in the top 5 genera, or to the top 3 species in each of the top 5 genera.</p>
<dd><p>a character string indicating the microorganism property to use for filtering. Must be one of the column names of the <ahref="microorganisms.html">microorganisms</a> data set: "mo", "fullname", "status", "kingdom", "phylum", "class", "order", "family", "genus", "species", "subspecies", "rank", "ref", "oxygen_tolerance", "source", "lpsn", "lpsn_parent", "lpsn_renamed_to", "mycobank", "mycobank_parent", "mycobank_renamed_to", "gbif", "gbif_parent", "gbif_renamed_to", "prevalence", or "snomed". If <code>NULL</code>, the raw values from <code>col_mo</code> will be used without transformation.</p></dd>
<dd><p>an optional integer specifying the maximum number of rows to retain for each value of the selected property. If <code>NULL</code>, all rows within the top <em>n</em> groups will be included.</p></dd>
<dd><p>A character string indicating the column in <code>x</code> that contains microorganism names or codes. Defaults to the first column of class <code><ahref="as.mo.html">mo</a></code>. Values will be coerced using <code><ahref="as.mo.html">as.mo()</a></code>.</p></dd>
<dd><p>Additional arguments passed on to <code><ahref="mo_property.html">mo_property()</a></code> when <code>property</code> is not <code>NULL</code>.</p></dd>
<p>This function is useful for preprocessing data before creating <ahref="antibiogram.html">antibiograms</a> or other analyses that require focused subsets of microbial data. For example, it can filter a data set to only include isolates from the top 10 species.</p>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 1</span> 2002-01-02 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 2</span> 2002-01-03 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 3</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 4</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 5</span> 2002-01-19 738003 71 M Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 6</span> 2002-01-19 738003 71 M Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 7</span> 2002-02-03 481442 76 M ICU B_STPHY_CONS R NA S NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 8</span> 2002-02-14 067927 45 F ICU B_STPHY_CONS R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 9</span> 2002-02-14 067927 45 F ICU B_STPHY_CONS S NA S NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;">10</span> 2002-02-21 A56499 64 M Clinical B_STPHY_CONS S NA S NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #949494;"># ℹ 1,005 more rows</span></span>
<spanclass="r-in"><span> n <spanclass="op">=</span><spanclass="fl">5</span>, property <spanclass="op">=</span><spanclass="st">"genus"</span><spanclass="op">)</span></span></span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #949494;"># A tibble: 1,742 × 46</span></span>
<spanclass="r-out co"><spanclass="r-pr">#></span> date patient age gender ward mo PEN OXA FLC AMX </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 1</span> 2002-01-02 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 2</span> 2002-01-03 A77334 65 F Clinical B_ESCHR_COLI R NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 3</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 4</span> 2002-01-07 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 5</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 6</span> 2002-01-13 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 7</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 8</span> 2002-01-14 462729 78 M Clinical B_STPHY_AURS R NA S R </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 9</span> 2002-01-16 067927 45 F ICU B_STPHY_EPDR R NA R NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;">10</span> 2002-01-17 858515 79 F ICU B_STPHY_EPDR R NA S NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #949494;"># ℹ 1,732 more rows</span></span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 1</span> 2002-02-21 4FC193 69 M Clinical B_ENTRC_FACM NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 2</span> 2002-04-08 130252 78 M ICU B_ENTRC_FCLS NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 3</span> 2002-06-23 798871 82 M Clinical B_ENTRC_FCLS NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 4</span> 2002-06-23 798871 82 M Clinical B_ENTRC_FCLS NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 5</span> 2003-04-20 6BC362 62 M ICU B_ENTRC NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 6</span> 2003-04-21 6BC362 62 M ICU B_ENTRC NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 7</span> 2003-08-13 F35553 52 M ICU B_ENTRC_FCLS NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 8</span> 2003-09-05 F35553 52 M ICU B_ENTRC NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;"> 9</span> 2003-09-05 F35553 52 M ICU B_ENTRC_FCLS NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #BCBCBC;">10</span> 2003-09-28 1B0933 80 M Clinical B_ENTRC NA NA NA NA </span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #949494;"># ℹ 1,487 more rows</span></span>
<spanclass="r-out co"><spanclass="r-pr">#></span><spanstyle="color: #949494;"># IPM <sir>, MEM <sir>, MTR <sir>, CHL <sir>, COL <sir>, MUP <sir>, …</span></span>
</code></pre></div>
</div>
</main><asideclass="col-md-3"><navid="toc"aria-label="Table of contents"><h2>On this page</h2>
</nav></aside></div>
<footer><divclass="pkgdown-footer-left">
<p><code>AMR</code> (for R). Free and open-source, licenced under the <atarget="_blank"href="https://github.com/msberends/AMR/blob/main/LICENSE"class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <atarget="_blank"href="https://www.rug.nl"class="external-link">University of Groningen</a> and <atarget="_blank"href="https://www.umcg.nl"class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>