Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How do I calculate the annual mean of ~40 sites

$
0
0

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.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>