Is there any way to find the sum, mean max for multiple variables simultaneously?
Consider the sample data below:
library(lubridate)
days = 365*2
date = seq(as.Date("2001-02-02"), length = days, by = "day")
year = year(date)
month = month(date)
a1 = cumsum(rnorm(days, 0.05))
a2 = cumsum(rnorm(days, 0.05))
data1 = data.frame(date, year, month, a1, a2)
I want to find the aggregate of a1 and a2 variables from the data2 data frame by year and month.
The below code aggregates the a1 variable, but is it possible to simultaneously aggregate the a2 variable.
# aggregate variables by year month
data2=aggregate(a1 ~ year+month, data=data1, sum, na.rm=TRUE)
head(data2)
Any help would be greatly appreciated.