-1
You can also use the package dplyr
library(dplyr)
summary <- dados %>%
mutate (Date = as.Date(Date, "%m/%d/%Y"),
Mes = as.Date(Date, "%Y%m")) %>%
group_by (Mes) %>%
summarise (Soma = sum (INTE_C1, na.rm=TRUE)) %>%
ungroup ()
If you wanted to apply this to all columns you can do as follows
summary <- dados %>%
mutate (Date = as.Date(Date, "%m/%d/%Y"),
Mes = as.Date(Date, "%Y%m")) %>%
group_by (Mes) %>%
summarise_at (vars(INTE_C1:SO2), sum, na.rm = TRUE) %>%
ungroup ()
If you foresee more functions you can use the following:
summary <- dados %>%
mutate (Date = as.Date(Date, "%m/%d/%Y"),
Mes = as.Date(Date, "%Y%m")) %>%
group_by (Mes) %>%
summarise_at (vars(INTE_C1:SO2), list (sum, mean, sd), na.rm = TRUE) %>%
ungroup ()
Another suggestion is to use working the data in the long format as follows:
library (tidyr)
summary <- dados %>%
mutate (Date = as.Date(Date, "%m/%d/%Y"),
Mes = as.Date(Date, "%Y%m")) %>%
gather (key = "Parametro", value = "Resultado", INTE_C1:SO2) %>%
group_by (Mes, Parametro) %>%
summarise (Soma = sum(Resultado, na.rm = TRUE),
Media = mean(Resultado, na.rm = TRUE)) %>%
ungroup ()
Welcome to Stackoverflow! Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please, take a look at this link and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.
– Marcus Nunes