I have large data set of stream chemistry for several streams for long periods of time (7-20 years worth of data). I want to obtain a monthly TOC value for every year for each site but there are times when there is only 1 TOC value for a given month while other months have 2 or more. When I use summarize (example below) I get NA's for instances with only 1 TOC value.
df_TOC <- df %>% group_by(Site,Year, Month) %>% summarise(AvgTOC=mean(TOC))
I would like some help on how to summarize the data with a condition statement something along the lines of:
If TOC has 2 or more values per month, then calculate the mean; if not then paste the single value for that month.
Site Month Year TOC
AAA Jan 1975 5
AAA Feb 1975 7
AAA Feb 1975 8
AAA March 1975 10
AAA March 1975 12
AAA April 1975 13
BBB Jan 1975 6
BBB Jan 1975 3
BBB Feb 1975 6
BBB Feb 1975 12
BBB Feb 1975 17
BBB March 1975 4