Questions tagged [zoo]

zoo is an R package that provides an S3 class with methods for totally ordered indexed observations.

zoo ("Z's Ordered Observations") is an package for analysis of regular and irregular time series.

It provides an class with methods for totally ordered indexed observations. It is particularly aimed at irregular of numeric vectors/matrices and factors. zoo's key design goals are independence of a particular index/date/time class and consistency with ts in base-R by providing methods to extend standard generics.

Repositories

Vignettes

Other resources

Related tags

1328 questions
6
votes
2 answers

Replace missing values with the mean of surroundings values

My dataset looks like the following (let's call it "a"): date value 2013-01-01 12.2 2013-01-02 NA 2013-01-03 NA 2013-01-04 16.8 2013-01-05 10.1 2013-01-06 NA 2013-01-07 12.0 I would like to replace the NA by the mean of the closest surroundings…
user2165907
  • 1,401
  • 3
  • 13
  • 28
6
votes
1 answer

What makes rollmean faster than rollapply (code-wise)?

I regularly find rolling things of time series (particularly means), and was surprised to find that rollmean is notably faster than rollapply, and that the align = 'right' methods are faster than the rollmeanr wrappers. How have they achieved this…
ricardo
  • 8,195
  • 7
  • 47
  • 69
6
votes
2 answers

R/zoo: index entries in ‘order.by’ are not unique

I have a .csv file containing 4 columns of data against a column of dates/times at one-minute intervals. Some timestamps are missing, so I'm trying to generate the missing dates/times and assign them NA values in the Y columns. I have previously…
James A
  • 655
  • 2
  • 7
  • 8
6
votes
2 answers

Producing a rolling average of ALL the previous observations per ID in an unbalanced panel data set

I am trying to compute rolling means of an unbalanced data set. To illustrate my point I have produced this toy example of my data: ID year Var RollingAvg(Var) 1 2000 2 NA 1 2001 3 2 1 2002 4 2.5 1 2003 2 3 2 2001 …
Mace
  • 1,259
  • 4
  • 16
  • 35
6
votes
1 answer

How to use zoo or xts with large data?

How can I use the R packages zoo or xts with very large data sets? (100GB) I know there are some packages such as bigrf, ff, bigmemory that can deal with this problem but you have to use their limited set of commands, they don't have the functions…
skan
  • 7,423
  • 14
  • 59
  • 96
6
votes
2 answers

Most efficient/vectorization when using previous calculated value (rolling)

Following those conversations: Can I vectorize a calculation which depends on previous elements sapply? tapply? ddply? dataframe variable based on rolling index of previous values of another variable I wanted to test a more "real-life"…
statquant
  • 13,672
  • 21
  • 91
  • 162
6
votes
3 answers

Forcing full weeks with apply.weekly()

I'm trying to figure out what xts (or zoo) uses as the time after doing an apply.period. Consider the following: > myTs = xts(1:10, as.Date(1:10, origin = '2012-12-1')) > apply.weekly(myTs, colSums) [,1] 2012-12-02 1 2012-12-09 …
Xodarap
  • 11,581
  • 11
  • 56
  • 94
6
votes
1 answer

suffixes in xts merge in R

When trying to merge to xts objects, it doesn't look like the suffixes arg is working properly: require(xts) x <- xts(1:10, seq.Date(from=as.Date("2012-01-01"), len=10, by=1)) y <- xts(11:20, seq.Date(from=as.Date("2012-01-01"), len=10,…
Alex
  • 19,533
  • 37
  • 126
  • 195
6
votes
0 answers

working with panel data in R

I would like to see what people use to work with panel data in R with large datasets (ie 50 mil + obs): the data.table package is useful in that it has keys and is very fast. The xts package is useful because it has facilities for doing all sorts…
Alex
  • 19,533
  • 37
  • 126
  • 195
6
votes
1 answer

No applicable method for 'time<-' applied to an object of class "c('xts', 'zoo')"

Please, put this data structure into R in order to reproduce my example: dX <- structure(c(3272.1, 3271.48, 3281.03, 3267.08, 3260.65, NA, 1616.3, 1620.1, 1639.9, 1637.4, 1669.6, 1662.2, 528.385, 529.268, 531.022, 532.424, NA, NA), .indexTZ = "",…
user1621969
  • 63
  • 1
  • 4
6
votes
3 answers

How to remove a row from zoo/xts object, given a timestamp

I was happily running with this code: z=lapply(filename_list, function(fname){ read.zoo(file=fname,header=TRUE,sep = ",",tz = "") }) xts( do.call(rbind,z) ) until Dirty Data came along with this at the end of one file: …
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
6
votes
2 answers

Efficiently removing missing values from the start and end of multiple time series in 1 data frame

Using R, I'm trying to trim NA values from the start and end of a data frame that contains multiple time series. I have achieved my goal using a for loop and the zoo package, but as expected it is extremely inefficient on large data frames. My data…
sizeight
  • 719
  • 1
  • 8
  • 19
5
votes
3 answers

Can rollapply return a list of matrices?

I would like to generate covariance matrices (and mean vectors) using a rolling window. But in all my attempts rollapply stacks the covariance matrices from cov and runs out of pre-allocated space (e.g., if my original data have 40 observations,…
Richard Herron
  • 9,760
  • 12
  • 69
  • 116
5
votes
2 answers

internal NA time series, zoo, R

I have a zoo object in R that has daily data and is missing the weekends. When I try to run some functions (for example ar() ) on the object i get the error: mkt.ar <- ar(zoo_object) Error in na.fail.default(as.ts(x)) : missing values in object If…
Alex
  • 19,533
  • 37
  • 126
  • 195
5
votes
1 answer

rollapply time series in R (zoo) on backward looking data

I would like to use the zoo function rollapply to apply a function (for example mean) on a time series but only using the last N known points. For example: x = zoo(c(1,2,3,4), order.by=c(10,11,12,13)) rollmean(x,2) Produces: 10 11 12 1.5 2.5 3.5…
Alex
  • 19,533
  • 37
  • 126
  • 195