-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.Rmd
55 lines (43 loc) · 1.08 KB
/
data.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: "Data"
---
Load the package.
```{r}
library(CoV19)
```
The data are in the following objects. They have a few common columns: date, region, positive, death. Then there are some other columns depending on the source.
```
states
italy
world
```
Here is an example from `states`:
```{r}
head(states)
```
# Subsetting data
```{r}
# Just WA
x <- subset(states, region=="WA")
# Two states
x <- subset(states, region %in% c("WA","CA"))
# All areas in China
x <- subset(world, stringr::str_detect(region, "China"))
```
# Merging Data
Let's say you want to have the sums for all regions. You can do that with `dplyr`.
```{r}
library(dplyr)
# If you are unfamiliar with dplyr, the %>% is a pipe that sends
# the result to the left into the function in the right
x <- states %>%
subset(region%in%c("WA","CA","OR")) %>%
group_by(date) %>%
summarize_if(is.numeric, sum, na.rm=TRUE)
# This will not have the region column, so we add that back on
x$region <- as.factor("WA + CA + OR")
```
We can pass this data object to `plot2` to plot.
```{r, message=FALSE, warning=FALSE}
plot2(x)
```