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

better way to extract number of unique days in a zoo object

My data looks like this guy below. > head(data) open high low close 2013-06-20 09:31:00 275.50 276.00 275.08 275.65 2013-06-20 09:32:00 275.61 276.88 275.61 276.67 2013-06-20 09:33:00 276.67 276.72 275.95 276.62 2013-06-20…
Taylor
  • 1,797
  • 4
  • 26
  • 51
0
votes
1 answer

time-weighted average in xts or zoo

How to calculate the time-weighted average of an xts object for e.g 5 minutes: I know weighted.mean() but don't know how to deal with the date and time. Thanks library(xts) structure(c(28.2, 28.2, 28.2, 28.2, 28.1, 28.1, 28.1, 28.1, 28.1,…
Herr Student
  • 853
  • 14
  • 26
0
votes
1 answer

R: Problems using rollapply to sum groups of columns

I have what should be a simple question, but I'm very new to R so it's stumping me. I have a series of 25 columns representing trials in a behavioral experiment. I would like to use roll apply to sum the first 5 columns, then 6-10, 11-15, and so on,…
0
votes
1 answer

How to use the "!is.na" function with zoo objects

I have problems using the is.na function with a zoo object. Here is what I tried: z1 <- zoo(matrix(1:8, 4, 2), as.Date("2003-01-01") + 0:3) z1[2,1]<-NA So, z1 is... 2003-01-01 1 5 2003-01-02 NA 6 2003-01-03 3 7 2003-01-04 4 8 When I use…
sts
  • 181
  • 1
  • 1
  • 3
0
votes
0 answers

R converting data.frame to zoo

I have a big data.frame where the whole dataset is loaded from a csv. Dates are stored like 20130614 in Column 1, which is in my case MergedSet$Date. How do I create a zoo object of this whole data.frame? I found some hints in other Posts but I…
MichiZH
  • 5,587
  • 12
  • 41
  • 81
0
votes
1 answer

Handling time with zoo in R

I'm trying to load time series in R with the 'zoo' library. The observations I have varying precision. Some have the day/month/year, others only month and year, and others year: 02/10/1915 1917 07/1917 07/1918 30/08/2018 Subsequently, I need to…
Mulone
  • 3,603
  • 9
  • 47
  • 69
0
votes
1 answer

Using apply with zoo objects

Below is example code of the issue I am having. It seems that zoo does not work with apply. Any suggestions on how to make this work as desired? > #I am trying to use apply with zoo > tmp <- zoo(matrix(c(0,1,0,0,0,1),nrow=3)) > tmp 1 0 0 2 1 0 3 0…
Rob Richmond
  • 855
  • 6
  • 19
0
votes
2 answers

Plotting multiple time series data ( long format ) into one plot?

Suppose i have 3 time series data "a","b","c", each of them has 2 variables to be record in 7 days. Here goes the sample code: require(data.table) #Create data DT<-data.table(type=c(rep("a",7),rep("b",7),rep("c",7)),…
JerseyGood
  • 191
  • 4
  • 15
0
votes
1 answer

Using loop for data formatting in R

I want to format lot's of df's in the same way - is it possible to write a loop? Let's call them df1, df2, df3,... df1$timestamp<-as.POSIXct(df1$timestamp,format="%Y-%m-%d…
Herr Student
  • 853
  • 14
  • 26
0
votes
1 answer

aggregate zoo object index classes date

Iam trying to merge zoo objects with different index classes. Because the index classes are different I have tried to aggregate the the first zoo object as index class date. > dput(ldr_fund) structure(c(0, 0.00711526523549466, -0.00967898190752514,…
dansan566
  • 91
  • 1
  • 7
0
votes
1 answer

Plotting truncated times from zoo time series

Let's say I have a data frame with lots of values under these headers: df <- data.frame(c("Tid", "Value")) #Tid.format = %Y-%m-%d %H:%M Then I turn that data frame over to zoo, because I want to handle it as a time series: library("zoo") df <-…
GaRyu
  • 115
  • 4
0
votes
1 answer

How to extract the dates in a separate file from a zoo file of security prices?

I'm trying to extract the dates in a separate file from a zoo file--specifically, the trading-day dates rather than standard calendar day dates. I download a series from Yahoo Finance as such: vti…
James Picerno
  • 472
  • 4
  • 16
0
votes
1 answer

How to merge couples of Dates and values contained in a unique csv

We have a csv file with Dates in Excel format and Nav for Manager A and Manager B as follows: Date,Manager A,Date,Manager…
Lorenzo Rigamonti
  • 1,705
  • 8
  • 25
  • 36
0
votes
1 answer

scalable carry forward in R to create daily time series

I'm attempting to create a daily time series dataset from what is currently observed only periodically. I can successfully perform the desired operation for a single case but can't work out how to scale to the entire dataset. For example: …
hubert_farnsworth
  • 797
  • 2
  • 9
  • 21
0
votes
1 answer

rollapply with embedded reference

My current code is this: Model <- head(rollapplyr(z, width = 131, function(x) fitted(lm(y ~x1+ x2, data = as.data.frame(x))), by.column = FALSE)[,131],3429) I would like to do this: fit1 <- lm(y ~x1+ x2) Model <- head(rollapplyr(z, width = 131,…