Skip to content

rollaply with list as width #214

Open
@BibeFiu

Description

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions