1XDAT <- .xts(c(1, NA, 3, 4, 5, 6), c(0, 4, 10, 19, 24, 29))
2XIDX <- .xts(rep(0, 5), c(5, 10, 20, 25, 28))
3MODES <- c("double", "integer", "character", "logical")
4
5test.naomit <- function() {
6  for (m in MODES) {
7    xdat <- XDAT
8    xidx <- XIDX
9    storage.mode(xdat) <- storage.mode(xidx) <- m
10    zdat <- as.zoo(xdat)
11    zidx <- as.zoo(xidx)
12
13    x <- na.omit(xdat)
14    z <- na.omit(zdat)
15    # na.omit.xts adds "index" attribute to the "na.action" attribute
16    attr(attr(x, "na.action"), "index") <- NULL
17    #checkIdentical(x, as.xts(z))  # FALSE (attribute order differs)
18    checkEquals(x, as.xts(z), check.attributes = TRUE)
19  }
20}
21
22test.naomit_by_column <- function() {
23  for (m in MODES) {
24    xdat <- XDAT
25    xidx <- XIDX
26    storage.mode(xdat) <- storage.mode(xidx) <- m
27    zdat <- as.zoo(xdat)
28    zidx <- as.zoo(xidx)
29
30    x <- na.omit(merge(one = xdat, two = xdat))
31    z <- na.omit(merge(one = zdat, two = zdat))
32    # na.omit.xts adds "index" attribute to the "na.action" attribute
33    attr(attr(x, "na.action"), "index") <- NULL
34    checkEquals(x, as.xts(z), check.attributes = TRUE)
35  }
36}
37