I am trying to modify existing code that calculates the mean of results within a dataframe and then assesses them over different averaging periods. First off, I would really love some help breaking down exactly what the existing chunk of code is doing since I am not familiar with the as.data.table function. Here is the existing code:
I am trying to pull specific data out of my dataframe to average on a monthly basis instead. I did this like so:
monthlymean<-W_Objectives[W_Objectives$Comment == "monthly mean",]
monthlymean <- monthlymean %>%
year=year(SampleDate), # extract parts
My first question is: should I extract the data to be evaluated by a monthly mean prior to running the first chunk?
My second question is regarding how I would format a monthly mean using the as.data.table function. I was originally planning on using the aggregate function using month and year, but if there is an easy way to do this using as.data.table it would keep the code more streamlined for future use.
I appreciate any guidance as I am fairly new to R!