I have a data frame with daily data from 40 sites and I need to calculate the annual mean of each site
Date Site1 Site2 Site3 Site4 Until site 40 01/01/2006 30 45 45 67 02/01/2006 40 89 89 56 03/01/2006 56 34 67 23 UNTIL 2014 89 34 43 45
library("xlsx")
Trial <- read.xlsx ("Trial.xlsx", sheetIndex = 1, header = TRUE)
Trial
Trial$Date <- as.Date(Trial$Date)
Trial$Month <-months(Trial$Date)
Trial$Year <-format(Trial$Date, format="%y")
Means <- aggregate(Site1 ~ Month + Year, Trial, mean)
All this works, but it calculates the monthly means, not the yearly ones, also and the most important, how can I apply this code to all the 40 sites, not only to Site 1.