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

rollaply with list as width #214

Open
BibeFiu opened this issue Apr 10, 2022 · 0 comments
Open

rollaply with list as width #214

BibeFiu opened this issue Apr 10, 2022 · 0 comments

Comments

@BibeFiu
Copy link

BibeFiu commented Apr 10, 2022

In zoo rollapply can have a list as width argument to specify offsets like:
z <- data.frame(date=as.Date(1:10),
x=1:10)
data.frame(dates=z$date,
rollapply(z$x,by.column=TRUE,
list(-3:-5) ,
mean,
fill=NA))
which calculates the mean of element 3 to 5 position before.

With tq_mutate
z %>%
tq_mutate(
select = x,
mutate_fun = rollapply,
width = list(-3:-5),
FUN = mean)
Error in rollapply.xts(., ...) :
'list' object cannot be coerced to type 'integer'
it seems that the rollapply.xts does not support width = list() while the rollapply.zoo does. Is there an option to use the zoo version of rollaply with tq_mutate or get an offset in some other way?

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