1

I have a dataframe with 2 column first: date-hour(every one hour one observation) and second column is temperature(th).I am trying to find What is the largest temperature change in my data series within a specific time (6 hours)? Consider both, rapid temperature increase and decrease. I implement a function to calculate the range between the max(x) and min(x) of a vector x. and then Use this function in the FUN = argument of the rollapply-function (from zoo package).

t_range<- function(x)diff(range(x))
th<-Th %>%  mutate(t06 = rollapply(th, 
                               width = 6, 
                               FUN = t_range, 
                               fill = NA, 
                               align= "right",
                               arrange = desc(th)))

But I faced the following error : unused argument (arrange = c(.....

what is the problem of arrange= .. here?

  • Remove `arrange = desc(th)`. `th <- Th %>% mutate(t06 = rollapply(th, width = 6, FUN = t_range, fill = NA, align= "right"))`. You can also use `rollapplyr` which has by default `align= "right"` – Ronak Shah Jan 12 '21 at 08:20
  • thank you. yes , now I understand the whole concept – Faranak omidi Jan 12 '21 at 08:39

1 Answers1

0

You can remove arrange = desc(th) from rollapply call. Include it before or after rollapply. Also rollapply(..., align = 'right') can be simplified with rollapplyr.

library(dplyr)

th<- Th %>%  
      mutate(t06 = zoo::rollapplyr(th,width = 6, FUN = t_range, fill = NA)) %>%
      arrange(desc(th))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213