EVOLUTION-MANAGER
Edit File: complete.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: Complete a data frame with missing combinations of data</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 complete {tidyr}"><tr><td>complete {tidyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Complete a data frame with missing combinations of data</h2> <h3>Description</h3> <p>Turns implicit missing values into explicit missing values. This is a wrapper around <code><a href="expand.html">expand()</a></code>, <code><a href="../../dplyr/html/mutate-joins.html">dplyr::left_join()</a></code> and <code><a href="replace_na.html">replace_na()</a></code> that's useful for completing missing combinations of data. </p> <h3>Usage</h3> <pre> complete(data, ..., fill = list()) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>A data frame.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Specification of columns to expand. Columns can be atomic vectors or lists. </p> <ul> <li><p> To find all unique combinations of <code>x</code>, <code>y</code> and <code>z</code>, including those not present in the data, supply each variable as a separate argument: <code>expand(df, x, y, z)</code>. </p> </li> <li><p> To find only the combinations that occur in the data, use <code>nesting</code>: <code>expand(df, nesting(x, y, z))</code>. </p> </li> <li><p> You can combine the two forms. For example, <code>expand(df, nesting(school_id, student_id), date)</code> would produce a row for each present school-student combination for all possible dates. </p> </li></ul> <p>When used with factors, <code>expand()</code> uses the full set of levels, not just those that appear in the data. If you want to use only the values seen in the data, use <code>forcats::fct_drop()</code>. </p> <p>When used with continuous variables, you may need to fill in values that do not appear in the data: to do so use expressions like <code>year = 2010:2020</code> or <code style="white-space: pre;">year = \link{full_seq}(year,1)</code>.</p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p>A named list that for each variable supplies a single value to use instead of <code>NA</code> for missing combinations.</p> </td></tr> </table> <h3>Details</h3> <p>If you supply <code>fill</code>, these values will also replace existing explicit missing values in the data set. </p> <h3>Examples</h3> <pre> library(dplyr, warn.conflicts = FALSE) df <- tibble( group = c(1:2, 1), item_id = c(1:2, 2), item_name = c("a", "b", "b"), value1 = 1:3, value2 = 4:6 ) df %>% complete(group, nesting(item_id, item_name)) # You can also choose to fill in missing values df %>% complete(group, nesting(item_id, item_name), fill = list(value1 = 0)) </pre> <hr /><div style="text-align: center;">[Package <em>tidyr</em> version 1.1.2 <a href="00Index.html">Index</a>]</div> </body></html>