user3683555
user3683555

Reputation: 115

Rollapply() backwards in R

Is there a way to apply rollapply() backwards say from 100 to 1 instead of 1 to 100 or should I sort my data first and then apply rollaplly()?

Upvotes: 1

Views: 600

Answers (1)

vrajs5
vrajs5

Reputation: 4126

Try this

z = 1:100
#Normal rollapply
rollapply(z, 2, mean)

#Reverese
rollapply(z[length(z):1], 2, mean)

Upvotes: 3

Related Questions