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
11
votes
3 answers

Rolling window over irregular time series

I have an irregular time series of events (posts) using xts, and I want to calculate the number of events that occur over a rolling weekly window (or biweekly, or 3 day, etc). The data looks like this: postid 2010-08-04 22:28:07 …
Eric W.
  • 814
  • 1
  • 8
  • 18
10
votes
2 answers

Error in ggplot.data.frame : Mapping should be created with aes or aes_string

I am having a trouble while extracting the path from a ggplot and am stuck with an error. The image given below explains the result I am looking for: (Done in image editor for explaining purpose) Let's assume that Plot 1 is my original plot. What…
user4993868
10
votes
2 answers

na.locf converts data from numeric to character

summary(DF) >fx_code date fx_spot fx_fwd implied_fx_vol AUD : 171 Min. :2000-01-31 Min. : 0.394 Min. :-320.000 Min. : 1.000 BRL : 171 1st Qu.:2003-07-31 1st Qu.: …
ec0n0micus
  • 1,075
  • 2
  • 12
  • 19
10
votes
4 answers

Write xts/zoo object to csv with index

> library(PerformanceAnalytics) > data(managers) > class(managers) [1] "xts" "zoo" > head(managers) HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 EDHEC LS EQ SP500 TR US 10Y TR US 3m TR 1996-01-31 0.0074 NA 0.0349 0.0222 NA NA …
zsljulius
  • 3,813
  • 8
  • 36
  • 61
10
votes
2 answers

Replace missing value with previous value

Event,Time,Bid,Offer Quote,0.458338,9.77,9.78 Order,0.458338,NA,NA Order,0.458338,NA,NA Order,0.458338,NA,NA Quote,0.458363,9.78,9.79 Order,0.458364,NA,NA I have a Data frame like this I want to write a efficient code to fill up the NA with…
user2033963
  • 111
  • 1
  • 3
9
votes
2 answers

rollapply with "growing" window

Guys, normally when you do something like: tmp = zoo(rnorm(100), 1:100) rollapply(tmp, 10, function(x) quantile(x, 0.05), align="right") Quite rightly rollapply will start calculating the value from the moment 10 elements are…
Dr G
  • 3,987
  • 2
  • 19
  • 25
9
votes
3 answers

Convert Excel numeric to date

I have a vector of numeric excel dates i.e. date <- c(42963,42994,42903,42933,42964) The output am I expecting when using excel_numeric_to_date function from janitor package and as.yearmon function from zoo…
Azam Yahya
  • 646
  • 1
  • 7
  • 10
9
votes
3 answers

Is there any way to force zoo::rollmean function to return a vector that is the same length as it's input? (or maybe use other function?)

input = cbind(c(3,7,3,5,2,9,1,4,6,4,7,3,7,4)) library(zoo) output = cbind(rollmean(input,4)) print(input) print(output) output: [,1] [1,] 3 [2,] 7 [3,] 3 [4,] 5 [5,] 2 [6,] 9 [7,] 1 [8,] 4 [9,] 6 [10,] …
rsk82
  • 28,217
  • 50
  • 150
  • 240
9
votes
1 answer

How can I alter a time series (XTS or ZOO) in R?

I am new to stackoverflow and fairly new to R but have searched long and hard and cannot find an answer to the following question. I have a number of data files that are temperature against a time series. I am importing the CSV as a ZOO object then…
phrozenpenguin
  • 677
  • 2
  • 7
  • 7
9
votes
1 answer

R: Setting limits to scale_x_yearqtr in ggplot for yearqtr (zoo)

I'm working with the data set resembling the extract below: head(nomis.lng.agg) quarter decile avg.val 1 2004 Q4 1 5.680000 2 2005 Q1 1 5.745763 3 2005 Q2 1 5.503341 4 2005 Q3 1…
Konrad
  • 17,740
  • 16
  • 106
  • 167
9
votes
2 answers

Convert data.frame to zoo

I want to convert a data.frame to a zoo object. My df looks like that: > (str(StockPriceReturns)) 'data.frame': 3036 obs. of 2 variables: $ Date : Factor w/ 3036 levels "01.01.2002","01.01.2003",..: 1 102 202 301 600 701 802 902 1001 1300…
user2051347
  • 1,609
  • 4
  • 23
  • 34
9
votes
3 answers

Using rollmean when there are missing values (NA)

I have a data set which has a couple of NA in it. I take a rolling mean and expect that when there is no NA in the window, the rolling mean should produce a number as opposed to NA, however, rollmeanr in zoo does not seem to do this.…
Alex
  • 19,533
  • 37
  • 126
  • 195
8
votes
1 answer

zoo object aggregation

Dear Community, the data I receive will be in a data frame: Var_1 Var_2 Date VaR_3 VaR_4 VaR_5 Var_6 1 4 2010-01-18 7 apple 10 sweet 2 …
John
  • 1,401
  • 2
  • 11
  • 12
8
votes
1 answer

na.locf but don't do trailing NAs

I have the following time series > y<- xts(1:10, Sys.Date()+1:10) > y[c(1,2,5,9,10)] <- NA > y [,1] 2011-09-04 NA 2011-09-05 NA 2011-09-06 3 2011-09-07 4 2011-09-08 NA 2011-09-09 6 2011-09-10 7 2011-09-11 8 2011-09-12…
R novice
  • 83
  • 3
8
votes
3 answers

How to use `apply.monthly` in a zoo object with several columns

I have a zoo object called pp with daily data and 77 columns that looks like this: X02R X03N X04K X04N X04R X06I X06N X08J X08P X09O X11O X12L X14N X15G X16K (...) 1961-01-01 8.3 5.2 3.2 0.0 8.7 5.2 15.0 7.2 11.5 13.0 0.0 4.9 …
sbg
  • 1,772
  • 8
  • 27
  • 45
1 2
3
88 89