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

rollapply regression "envir" error

I have this data set https://gist.github.com/natemiller/42eaf45747f31a6ccf9a I'm trying to apply a rolling regression using the rollapply in the zoo package, following the examples in the rollapply help and keep getting what I imagine is a simple…
Nate Miller
  • 386
  • 5
  • 19
0
votes
2 answers

How to calculate moving average from text file?

I have one text file. I want to do some calculations (moving average) as shown below and write the results. The text file contains 15 columns and 601 rows. columns <- paste0("X", 1:13) ref <- read.table("D:\\DAS_asc.txt",…
Jonsson Sali
  • 73
  • 1
  • 10
0
votes
1 answer

Trouble with sapply

Here is the reproductible example (at least on my computer) a <- as.Date(as.Date("2012-10-01"):as.Date("2013-03-25")) myFun <- function (x) { return(sqrt(abs(as.numeric(x-as.Date("2013-01-01"))))) } for (i in 1:length(a)) { …
Chapo
  • 2,563
  • 3
  • 30
  • 60
0
votes
1 answer

Troubles in applying the zoo aggregate function to a time series

We have the following function to compute monthly returns from a daily series of prices: PricesRet = diff(Prices)/lag(Prices,k=-1) tail(PricesRet) # Monthly simple returns MonRet = aggregate(PricesRet+1, as.yearmon, prod)-1 tail(MonRet) The problem…
Lorenzo Rigamonti
  • 1,705
  • 8
  • 25
  • 36
0
votes
1 answer

Replace value in element class zoo

I have two time series of the same length of class zoo. One of them as NA value for some dates while the other one is completely filled by value. Since I need to plot some pie charts, I would need to disregard the dates with NA values also in the…
user1256539
0
votes
1 answer

Sampling with replacement from zoo timeseries objects

I'm trying to create a bagging algorithm. for this I need to draw random blocks from the whole time series. I created an index vector that contains the random block draws, but when i want to apply it on my zoo time series, i get the In zoo(rval,…
0
votes
0 answers

xts microsecond issue

Saved an xts object in .RData file and then opened it again in another R instance. I lose the microsecond timestamp. I keep the same configs in both environments including digits.secs=6. yum <- structure(c(262, 262, 262, 100, 100, 100, 120, 370,…
shoonya
  • 292
  • 1
  • 10
0
votes
1 answer

Restricting Time Sample in R

I am trying to plot a chart of some data I have loaded into R. But I only want a chart from one specific time period to another. How does one restrict on the sample of the data for certain time periods, say from 09/20/2010 to 09/23/2010. If I used…
gabriel
  • 399
  • 2
  • 7
  • 17
0
votes
1 answer

Error on loading zoo library

I'm trying to use the zoo package but unfortunately it's showing an error when I try use it. As a matter of fact, the results that I'm getting are wrong in the last line. > library(zoo) Attaching package: ‘zoo’ The following object(s) are masked…
Gekko
  • 5
  • 1
  • 4
0
votes
1 answer

Error reading in date using Zoo in R

I am trying to use the Zoo package to read in daily observations, some of which are not consecutive. The first three lines are: Date Year ID DWT Build CargoSize LoadArea DischargeArea Price Speed 25-May-07 2007 8004351 …
Sassafras
  • 301
  • 5
  • 16
0
votes
2 answers

combining data frame with a zoo object

I have a data set in a zoo object. I am looping through rows, extracting variables from them, and running those through a function that outputs a data frame for each row. I then combine these output data into a data frame which has rows that match…
mooseo
  • 163
  • 1
  • 1
  • 6
0
votes
1 answer

Declare yearly data in read.zoo

I am trying to read in yearly data with gaps using the read.zoo function from the zoo package. I am having some trouble finding the FUN that declares the data to be yearly data. The data set is located here. The function call I am trying is tsGDP…
tchakravarty
  • 10,736
  • 12
  • 72
  • 116
0
votes
1 answer

Regression with xts object, determine t-statistic of slope coefficient using R

I posted this question yesterday but received some valuable feedback that my post left a little to be desired :). Here is an updated attempt that hopefully is much clearer: I have a xts zoo object and would like to determine the t-statistic of the…
AdmiralF
  • 113
  • 2
  • 8
0
votes
3 answers

How to drop decimal precision when writing a zoo object to csv file with R?

When writing out a zoo object to a CSV file using write.zoo(), I would actually like to drop decimal precision from the default of 14 to just 3. However, even with setting scipen & digits in options(), I have not been able to drop the precision in…
Antony
  • 5,414
  • 7
  • 27
  • 32
0
votes
1 answer

Error convering character value to monthly data with as.yearmon (zoo)

Problem occurs when months' value are in the text form like "Jan" or "January". for example, the following line as.yearmon("Jan-2000", "%b-%Y") returns an error: Error in charToDate(x) : > character string is not in a standard unambiguous…