I have this table already in variable DATA in R, loaded from csv
country, date, confirmed
Afghanistan, 2020-03-16, 21
Afghanistan, 2020-03-17, 22
Afghanistan, 2020-03-18, 22
Albania, 2020-03-16, 23
Albania, 2020-03-17, 33
Albania, 2020-03-18, 38
...
I would like to make this query in R
select date, sum(confirmed) as confirmed FROM `Table` group by date
Any idea pls ?
So results should be this
date,confirmed
2020-03-16, 44
2020-03-17, 55
2020-03-18, 60
With aggregate
from base R
aggregate(confirmed ~ date, Table, sum, na.rm = TRUE)
Or with dplyr
library(dplyr)
Table %>%
group_by(date) %>%
summarise(confirmed = sum(confirmed, na.rm = TRUE))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments