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

Fastest way for doing 21 day rolling sum for an ActivityType

I have a large dataframe(3M+ rows). I am trying to count the number of times a certain ActivityType appears in a 21 day window. I have modelled my solution from Rolling Sum by Another Variable in R. But it takes a long time just for one…
gibbz00
  • 1,947
  • 1
  • 19
  • 31
8
votes
1 answer

What is the difference the zoo object and ts object in R?

I want to know the differences into use ts() or zoo() function.
xusliebana
  • 303
  • 1
  • 4
  • 11
8
votes
6 answers

calculating sum of previous 3 rows in R data.table (by grid-square)

I would like to calculate the rainfall that has fallen over the last three days for each grid square, and add this as a new column in my data.table. To be clear, I want to sum up the current and PREVIOUS two (2) days of rainfall, for each…
threeisles
  • 301
  • 2
  • 8
8
votes
2 answers

which time series class to use in R for financial data?

for working with financial time series, like daily stock prices or intraday data, which time series packages are preferred? xts, plain zoo, or timeSeries or something else? I use both xts and zoo, but sometimes not sure to use xts exclusively or…
ahala
  • 81
  • 2
8
votes
1 answer

How to add multiple straight lines in a multi plot.zoo

I have multiple time series data plots and I need an horizontal line in each plot but with different horizontal values (es. 1st plot: h=50, 2nd plot: h=48...). I tried abline(h=50... and I get the horizontal line in each plot. I tried…
daniele
  • 149
  • 1
  • 3
  • 9
8
votes
3 answers

Check the frequency of time series data

Assume: I have a time series data, either a zoo or xts object. Question: Is there any convenient function or method so that I can check whether the time series is monthly, quarterly or yearly?
L.J
  • 1,066
  • 2
  • 13
  • 28
8
votes
2 answers

Add missing xts/zoo data with linear interpolation in R

I do have problems with missing data, but I do not have NAs - otherwise would be easier to handle... My data looks like this: time, value 2012-11-30 10:28:00, 12.9 2012-11-30 10:29:00, 5.5 2012-11-30 10:30:00, 5.5 2012-11-30 10:31:00, 5.5 2012-11-30…
Herr Student
  • 853
  • 14
  • 26
8
votes
2 answers

Creating regular 15-minute time-series from irregular time-series

I have an irregular time-series (with DateTime and RainfallValue) in a csv file C:\SampleData.csv: DateTime,RainInches 1/6/2000 11:59,0 1/6/2000 23:59,0.01 1/7/2000 11:59,0 1/13/2000 23:59,0 1/14/2000 0:00,0 1/14/2000 23:59,0 4/14/2000…
akashwani
  • 105
  • 1
  • 1
  • 7
7
votes
4 answers

Replacement for diff() for multiple columns

diff() calculates the difference between values in a vector at a specified lag. Is there an equivalent function that works on two vectors? For example, I have: v1 = c(1, 2, 3, 4, 5, 3) v2 = c(5, 4, 3, 2, 1, 0) I need to calculate the difference…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
7
votes
1 answer

Using the file name to name a column

I have hundreds of csv files (zoo objects in R) with 2 columns: "Index","pp" 1951-01-01,22.9 1951-01-02,4.3 1951-01-03,4.6 I want the second column to have the name of each file. For example, when a filename is 02O_zoo.csv I would like the…
sbg
  • 1,772
  • 8
  • 27
  • 45
7
votes
3 answers

Error when performing an NA replacement in R 4.0

With R 3.6 I can perform the following NA replacement > d <- zoo(data.frame(a = NA, b = 1), Sys.Date()) > d[is.na(d)] <- 1 > d a b 2021-03-03 1 1 With R 4.0 I get the following error: > d <- zoo(data.frame(a = NA, b = 1), Sys.Date()) >…
billelev
  • 369
  • 2
  • 13
7
votes
3 answers

Compute running mean with tapered windows

Given a (dummy) vector index=log(seq(10,20,by=0.5)) I want to compute the running mean with centered window and with tapered windows at each end, i.e. that the first entry is left untouched, the second is the average of a window size of 3, and so…
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
7
votes
1 answer

na.locf using group_by from dplyr

I'm trying to use na.locf from package zoo with grouped data using dplyr. I'm using the first solution on this question: Using dplyr window-functions to make trailing values (fill in NA values) library(dplyr);library(zoo) df1 <-…
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56
7
votes
3 answers

Count cumulative unique factors separated by semicolon Grouped by Name

This is what my dataframe looks like. The two rightmost columns are my desired columns. I am counting the cumulative number of unique FundTypes as of each row.The 4th columns is the cumulative unique count for all "ActivityType" and the 5th column…
gibbz00
  • 1,947
  • 1
  • 19
  • 31
7
votes
2 answers

R: Interpolation of NAs by group

I would like to perform a linear interpolation in a variable of a data frame which takes into account the: 1) time difference between the two points, 2) the moment when the data was taken and 3) the individual taken for measure the variable. For…
Ruben
  • 493
  • 4
  • 18