EVOLUTION-MANAGER
Edit File: na.omit.data.table.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: Remove rows with missing values on columns specified</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 na.omit.data.table {data.table}"><tr><td>na.omit.data.table {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Remove rows with missing values on columns specified </h2> <h3>Description</h3> <p>This is a <code>data.table</code> method for the S3 generic <code>stats::na.omit</code>. The internals are written in C for speed. See examples for benchmark timings. </p> <p><code>bit64::integer64</code> type is also supported. </p> <h3>Usage</h3> <pre> ## S3 method for class 'data.table' na.omit(object, cols=seq_along(object), invert=FALSE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p> A <code>data.table</code>. </p> </td></tr> <tr valign="top"><td><code>cols</code></td> <td> <p> A vector of column names (or numbers) on which to check for missing values. Default is all the columns. </p> </td></tr> <tr valign="top"><td><code>invert</code></td> <td> <p> logical. If <code>FALSE</code> omits all rows with any missing values (default). <code>TRUE</code> returns just those rows with missing values instead. </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> Further arguments special methods could require. </p> </td></tr> </table> <h3>Details</h3> <p>The <code>data.table</code> method consists of an additional argument <code>cols</code>, which when specified looks for missing values in just those columns specified. The default value for <code>cols</code> is all the columns, to be consistent with the default behaviour of <code>stats::na.omit</code>. </p> <p>It does not add the attribute <code>na.action</code> as <code>stats::na.omit</code> does. </p> <h3>Value</h3> <p>A data.table with just the rows where the specified columns have no missing value in any of them. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code> </p> <h3>Examples</h3> <pre> DT = data.table(x=c(1,NaN,NA,3), y=c(NA_integer_, 1:3), z=c("a", NA_character_, "b", "c")) # default behaviour na.omit(DT) # omit rows where 'x' has a missing value na.omit(DT, cols="x") # omit rows where either 'x' or 'y' have missing values na.omit(DT, cols=c("x", "y")) ## Not run: # Timings on relatively large data set.seed(1L) DT = data.table(x = sample(c(1:100, NA_integer_), 5e7L, TRUE), y = sample(c(rnorm(100), NA), 5e7L, TRUE)) system.time(ans1 <- na.omit(DT)) ## 2.6 seconds system.time(ans2 <- stats:::na.omit.data.frame(DT)) ## 29 seconds # identical? check each column separately, as ans2 will have additional attribute all(sapply(1:2, function(i) identical(ans1[[i]], ans2[[i]]))) ## TRUE ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>data.table</em> version 1.14.4 <a href="00Index.html">Index</a>]</div> </body></html>