Trim Leading/Trailing Missing Observations
na.trim.RdGeneric function for removing leading and trailing NAs.
Arguments
- object
an object.
- sides
character specifying whether
NAs are to be removed from both sides, just from the left side or just from the right side.- is.na
If "any" then a row will be regarded as
NAif it has anyNAs. If "all" then a row will be regarded asNAonly if all elements in the row areNA. For one dimensional zoo objects this argument has no effect.- maxgap
maximum number of consecutive
NAs to trim. Any longer gaps will be left unchanged.- ...
further arguments passed to methods.
Examples
# examples of na.trim
x <- zoo(c(1, 4, 6), c(2, 4, 6))
xx <- zoo(matrix(c(1, 4, 6, NA, 5, 7), 3), c(2, 4, 6))
na.trim(x)
#> 2 4 6
#> 1 4 6
na.trim(xx)
#>
#> 4 4 5
#> 6 6 7
# using na.trim for alignment
# cal defines the legal dates
# all dates within the date range of x should be present
cal <- zoo(,c(1, 2, 3, 6, 7))
x <- zoo(c(12, 16), c(2, 6))
na.trim(merge(x, cal))
#> 2 3 6
#> 12 NA 16