[R] reverse direction with rollapply()

Joshua Wiley jwiley.psych at gmail.com
Thu Jul 22 00:59:14 CEST 2010


Hello,

I am using rollapply() from package zoo to use a function on unique
windows from a dataset.  Because my dataset is not a multiple of my
window width, it matters which end I start at.  Here is a simple
example, the result I want is 7.5 (i.e., start at the highest level of
my ordering variable).  I thought that the argument ascending = FALSE
would do it, but it does not seem to have an effect.  It seems like I
must be missing something simple.

#Library and sample data
library(zoo)
mydata <- zoo(x = 6:8, order.by = 1:3)

rollapply(data = mydata, width = 2, by = 2,
  FUN = mean, ascending = TRUE, align = "left")

#This gives the same results
rollapply(data = mydata, width = 2, by = 2,
  FUN = mean, ascending = FALSE, align = "left")


Thanks,

Josh

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list