I have a dataset as below with five columns:Date, WeekNum, Year,Total Hours, Total Production
I want to sum my Total Hours by weeknum and year, also sum total production by weeknum and year, then use the first sum divided by second sum.
I know I can use aggregate function, for example:
sum1<-aggregate(list(TotalHours=input$TotalHours), by = list(Year=input$Year, WeekNum=input$WeekNum), FUN=sum)
sum2<-aggregate(list(TotalProduction=input$TotalProduction), by = list(Year=input$Year, WeekNum=input$WeekNum), FUN=sum)
then use sum1/sum2
However if there any easy way to simply this code or there is another function can help me to do that.
Thanks