1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
R version 3.1.1 (2014-07-10) -- "Sock it to Me"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> ## packages
> library("zoo")
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
> library("timeDate")
>
> ## aggregate() with "timeDate" index
> z <- zoo(1:3, timeDate(c("2011-09-19 12:00", "2011-09-19 12:00", "2011-09-19 13:00")))
Warning message:
In zoo(1:3, timeDate(c("2011-09-19 12:00", "2011-09-19 12:00", "2011-09-19 13:00"))) :
some methods for "zoo" objects do not work if the index entries in 'order.by' are not unique
> aggregate(z, identity, mean)
2011-09-19 12:00:00 2011-09-19 13:00:00
1.5 3.0
>
> ## assignment and preservation of column names in merge()
> x <- zoo(cbind(a = 3:4, b = 5:6))
> y <- zoo(1:2)
> merge(x, zoo(, time(x)))
a b
1 3 5
2 4 6
> merge(y, x)
y a b
1 1 3 5
2 2 4 6
>
> ## [<-.zoo with logical row index
> z <- zoo(cbind(1:5, 11:15), 101:105)
> z[index(z) == 103, 1] <- 0
>
> ## rollapply(..., mean, partial = TRUE)
> z <- zoo(11:15)
> identical(rollapply(z, 3, mean, partial = TRUE),
+ rollapply(z, 3, (mean), partial = TRUE))
[1] TRUE
>
> ## rollmedian(..., k = 1)
> z <- zoo(sin(0:20))
> identical(z, rollmedian(z, 1))
[1] TRUE
> identical(coredata(rollmedian(z, 1)), as.vector(runmed(coredata(z), 1)))
[1] TRUE
>
> ## na.fill with just NAs (directly and implicitly through rollapply)
> na.fill(c(NA, NA), fill = NA)
[1] NA NA
> rollapply(1:2, 3, sum, fill = NA)
[1] NA NA
>
> proc.time()
user system elapsed
1.044 0.036 1.072
|