Thank you very much for the quick response! One last question..
Lets say, I have a function for calculating the 5th quantile:
q05 <- function(var) {
return(quantile(var, 0.05, na.rm = T))
}
Now I want to call this function in grouping a given dataframe:
X = data.frame("myDate" = c("2015-01-01","2016-01-01","2017-01-01","2018-01-01","2019-01-01","2020-01-01"),
"var1" = c(1,2,3,4,5,6),
"var2" = c(2,2,2,4,4,4)
)
The following line does not work like I would expect:
myFunc<- function(df, myVar, myDateCol) {
result = df%>%
group_by("Date" = df[,myDateCol]) %>%
summarise("5th quantile" = q05(df[,myVar]))
return(result)
}
How can I group the dataframe and get my calculations over time?
I already worked with tapply here, but I could not manage to get it work for multiple functions e.g. q95