Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple columns in a sliding window, runner package, xts format #99

Open
mytarmail opened this issue Jun 11, 2024 · 0 comments
Open

multiple columns in a sliding window, runner package, xts format #99

mytarmail opened this issue Jun 11, 2024 · 0 comments

Comments

@mytarmail
Copy link

I'm trying to do something similar to w1, which contains colums in a sliding window of size k

set.seed(1)
library(xts)
tm <- Sys.time()+1:5000
x <- rnorm(5000) |> cumsum() |> round(1) |> xts(tm) |> to.minutes5(name = NULL) |> align.time()+100

# window len
k <- 3
w1 <- as.zoo(x) |> rollapplyr(width=k, FUN=c, fill=NA)

I'm trying to get the same thing as w1 using the runner package but I'm doing something wrong. This solution does not work although it is indicated that the package works with the xts format

library(runner)
w2 <- runner(x, k=k, f=c, na_pad = T) 

I made a workaround to make it work, but I would like to know how to do it correctly and non-redundantly.

w2 <- x |> 
      coredata() |> 
      runner(k=k, f=c, na_pad = T) |> 
      do.call(what="rbind") |> 
      xts(index(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant