Bug 15399 - na.omit.data.frame creates rows on an empty data.frame()
na.omit.data.frame creates rows on an empty data.frame()
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Analyses
R 3.0.1
Other Linux
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-07-20 21:13 UTC by Martin Morgan
Modified: 2013-07-21 13:05 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Morgan 2013-07-20 21:13:32 UTC
invoking na.omit on a zero-row data.frame returns a one-row data.frame.

> na.omit(data.frame())
data frame with 0 columns and 1 rows

similarly for na.exclude

> na.exclude(data.frame())
data frame with 0 columns and 1 rows


A fix is

Index: src/library/stats/R/nafns.R
===================================================================
--- src/library/stats/R/nafns.R	(revision 63365)
+++ src/library/stats/R/nafns.R	(working copy)
@@ -61,7 +61,7 @@
 {
     ## Assuming a data.frame like object
     n <- length(object)
-    omit <- FALSE
+    omit <- logical(nrow(object))
     vars <- seq_len(n)
     for(j in vars) {
 	x <- object[[j]]
@@ -115,7 +115,7 @@
 {
     ## Assuming a data.frame like object
     n <- length(object)
-    omit <- FALSE
+    omit <- logical(nrow(object))
     vars <- seq_len(n)
     for(j in vars) {
 	x <- object[[j]]
Comment 1 Duncan Murdoch 2013-07-21 13:05:57 UTC
Thanks, will fix in R-devel and R-patched.