Questions tagged [rollapply]

rollapply is a function in the zoo package used to perform rolling operations on an object.

rollapply is a function in the zoo package used to apply operations sequentially over elements of an object. Examples are returning a rolling mean for a vector or performing a regression on each of several partially-overlapping subsets, or rolling subsets, of a data set.

256 questions
0
votes
1 answer

Rollapply function does not work

My data is as below: gvkey datadate fyear cusip curcd at ceq csho dltt dvc nopi oibdp 1: 1001 12/31/1981 1981 000165100 USD NA NA NA NA NA NA NA 2: 1001 12/31/1982 1982 000165100 USD …
Bobo
  • 151
  • 1
  • 1
  • 8
0
votes
0 answers

find last row of data in rollapply

I am using the rollapply function to create a rolling logit estimation. The function is doing its job properly so far, but I would now like to extract for each iteration of the data the last values of that specific window to use these for the…
harryb
  • 41
  • 2
  • 6
0
votes
1 answer

Avoiding NA in rolling sums of last n observations within by groups using data.table

According to this threat I learned, rolling sums for variable b in the following data.table can be achieved as follows: data creation + computing rolling sums: x <- data.table(a = sample(letters[1:3], 100, replace = TRUE), b = runif(100)) …
0
votes
0 answers

Automate calculation of Area under curve of moving window

I am trying to find the area under a solar radiation intensity graph at a series of continuous time points. Basically I want the integral of the past 24hours of solar radiation every hour over a 7 day period - a moving sum of the past 24 hours - (I…
Kyle B.
  • 13
  • 4
0
votes
0 answers

Data.table column generated with function taking multiple, cumulative and lagged arguments

I'm trying to add a column to a data.table, where that column of the data.table is populated by passing the cumulative (lag 1) vector of values per group as well as a group-level attribute to a function, and then returning the appropriate value. I…
Karthik
  • 31
  • 3
0
votes
1 answer

Optimizing rollapplyr custom function

I have the following data: y <- data.table(cbind(week = rep(1:61,5352), ID = rep(1:5352, each = 61), w = runif(326472), v = runif(326472))) y$v[sample(1:326472, 10000, replace=FALSE)] <- NA for which I'm running the code bellow that creates a…
user1482923
  • 211
  • 3
  • 11
0
votes
1 answer

Error in rollapply: subscript out of bounds

I'd first like to describe my problem: What i want to do is to calculate the number of spikes on prices in a 24 hour window, while I possess half hourly data. I have seen all Stackoverflow posts like e.g. this one: Rollapply for time series (If…
fußballball
  • 329
  • 1
  • 14
0
votes
1 answer

Rollapply for row in R with exp function

I have the data frame df(A) with 14 col and 1356 row. I have this function, for to apply a sum for every 12 row, like a moving average: rollapply(A,width=12, FUN= sum,by.column=T) But inside every 12 row i need to apply a multiplication for…
Diego
  • 633
  • 1
  • 9
  • 16
0
votes
0 answers

R rollapply on a separate column

I have a dataframe: table <- data.frame(timestamp = c(1,1,1,3,4,6), category= c("one", "two", "one", "one", "one", "one")) I would like to print out a rolling average of how many unique categories there are with a window of 3 from 1 to…
puslet88
  • 1,288
  • 15
  • 25
0
votes
1 answer

rollaplly for time series

I have a data set with 358 rows, a quick look is as follows > unempts gdpts > [1,] 7.03 4.2 > [2,] 7.17 3.7 > [3,] 6.97 3.2 > [4,] 6.83 2.9 > [5,] 6.60 2.7 > [6,] 6.27 3.4 I need to run a regression of Column 1…
0
votes
0 answers

How to extract the index of the vector that rollapply is currently feeding to the function?

I'm looking to do some correlation work on two times series represented by 2 columns in a datatable. I basically need to be able to run rollapply on one column and be able to access another column in the called function using the current position of…
Wicelo
  • 2,358
  • 2
  • 28
  • 44
0
votes
0 answers

Loop Over Columns to perform Rolling Regression

This post sort of gets to my question :Linear Regression loop for each independent variable individually against dependent However, I am trying too add rolling periods for the regression. Example: data…
user2662565
  • 509
  • 2
  • 9
  • 22
0
votes
1 answer

Rolling Window adfTest with fix starting point

So I want to run the adfTest with lag=0 and type="c" in a loop, so the starting window is of length=5 and the finish window is lenght=nrow(Data). The thing is that i want that the starting window is fix so if the data contains 10 data point the…
Alejandro Andrade
  • 2,196
  • 21
  • 40
0
votes
2 answers

rollapply mean 5 previuous years

I have a zoo obj like that colled z. > z["2013-12",1] Allerona 2013-12-01 0.0 2013-12-02 0.0 2013-12-03 0.0 2013-12-04 0.0 2013-12-05 0.2 2013-12-06 0.0 2013-12-07 0.0 2013-12-08 0.2 2013-12-09 …
0
votes
2 answers

convert List to zoo and use rollapply on the List

I would like to convert a list object to zoo and then apply rollapply on the zoo object. Short example reproduced below (I have 90,000 such files to process, using UNIX:)). Assume my list has two dataframes. 1) I would like to convert the date in…
code123
  • 2,082
  • 4
  • 30
  • 53