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
7
votes
2 answers

Converting zoo to ts before forecasting

I am struggling to convert a zoo objects to a ts object. I have a huge data.frame "test" with quarterly hour data, which looks like this: date <- c("2010-07-04 09:45:00", "2010-07-04 10:00:00", "2010-07-04 10:15:00", "2010-07-04 10:30:00",…
Ruben
  • 125
  • 1
  • 4
7
votes
3 answers

Convert daily to weekly/monthly data with R

I have daily prices series over a wide range of products; I want to convert to a new dataframe with weekly or monthly data. I first used xts in order to apply the to.weekly function...which works only for OHLC format. I am sure there may exist a…
saradi
  • 141
  • 1
  • 1
  • 7
7
votes
3 answers

Why is there no apply.hourly in R with xts/zoo?

I want to aggregate data by hourly mean. Daily is very easy: apply.daily(X2,mean) Why is there no function for hourly? I tried hr.means <- aggregate(X2, format(X2["timestamp"],"%Y-%m-%d %H")) and got always error with trim argument. Is there an…
Herr Student
  • 853
  • 14
  • 26
7
votes
3 answers

Interpolation of time series data with specific output time

I have database with time data. I want to interpolate the data to mach e specific time step. Id Time humid humtemp prtemp press t 1 2012-01-21 18:41:50 47.7 14.12 13.870 1005.70 -0.05277778 1 2012-01-21…
Marco Giuliani
  • 241
  • 2
  • 9
7
votes
2 answers

Date format for plotting x axis ticks of time series data

The data files have date is the format i.e. 1975M1, 1975M2, ... 2011M12 for time series data. when plotting this data using R, I want the x-axis to display the months on tick axis. For the dates to be read properly, I have tried replacing the M by…
Anusha
  • 1,716
  • 2
  • 23
  • 27
7
votes
2 answers

Splitting irregular time series into regular monthly averages - R

In order to establish seasonal effects on energy use, I need to align the energy use information that I have from a billing database with monthly temperatures. I'm working with a billing dataset that has bills of varying lengths and start and end…
bikeclub
  • 369
  • 2
  • 10
6
votes
2 answers

What is the best method to bin intraday volume figures from a stock price timeseries using XTS / ZOO etc in R?

For instance, let's say you have ~10 years of daily 1 min data for the volume of instrument x as follows (in xts format) from 9:30am to 4:30pm : Date.Time Volume 2001-01-01 09:30:00 1200 2001-01-01 09:31:00 …
n.e.w
  • 1,128
  • 10
  • 23
6
votes
1 answer

sparseIndexTracking 0.1.0 failure in if(): missing value where TRUE/FALSE needed

I have two datasets. Both are xts objects. > dput(head(all_data[,2:3])) structure(c(0.00108166576527857, 0.00324149108589955, 0, 0, 0.00484652665589658, 0.00267952840300101, 0.00606980273141122, 0.00301659125188536, …
Alex Bădoi
  • 830
  • 2
  • 9
  • 24
6
votes
1 answer

Avoid (as)data.frame change data to factors when converting from zoo object

If you have a data.frame with numeric columns the conversion is without problems, as explained here. dtf=data.frame(matrix(rep(5,10),ncol=2)) #str(dtf) dtfz <- zoo(dtf) class(dtfz) #[1] "zoo" str(as.data.frame(dtfz)) #'data.frame': 5 obs. of 2…
Robert
  • 5,038
  • 1
  • 25
  • 43
6
votes
1 answer

roll applying multiple quantiles in data table to multiple columns

Background: I can get multiple moments from my data using data.table (see appended), but it is taking a very long time. I was thinking that the process of sorting the table to get a particular percentile would be more efficient for finding…
EngrStudent
  • 1,924
  • 31
  • 46
6
votes
1 answer

Differentiate missing values from main data in a plot using R

I create a dummy timeseries xts object with missing data on date 2-09-2015 as: library(xts) library(ggplot2) library(scales) set.seed(123) seq <- seq(as.POSIXct("2015-09-01"),as.POSIXct("2015-09-02"), by = "1 hour") ob1 <-…
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65
6
votes
1 answer

R remove groups with only NAs

I have a dataframe similar to the one generated by the following structure: library(dplyr) df1 <- expand.grid(region = c("USA", "EUR", "World"), time = c(2000, 2005, 2010, 2015, 2020), scenario =…
roming
  • 1,165
  • 1
  • 9
  • 22
6
votes
1 answer

use rollapply and zoo to calculate rolling average of a column of variables

I want to calculate the rolling mean for all variables in column "sp". This is a sample of my data: the_date sp wins 01-06--2012 1 305 02-06--2012 1 276 03-06--2012 1 184 04-06--2012 1 248 05-06--2012 1 243 06-06--2012 1 …
asiehh
  • 553
  • 12
  • 22
6
votes
1 answer

Faster alternative to function 'rollapply'

I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited…
Jairaj Gupta
  • 347
  • 4
  • 16
6
votes
2 answers

Rolling Standard Deviation in a Matrix in R

Bellow is a stock daily returns matrix example (ret_matriz) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489…
RiskTech
  • 1,135
  • 3
  • 13
  • 19