-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCS_15.Rmd
58 lines (43 loc) · 1.34 KB
/
CS_15.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
56
57
58
---
title: Final Challenge
week: 12
type: Case Study
---
## Write a short script to perform the following steps
1. Import the data on atmospheric $CO_2$ from the link below into R
```{r}
data_url="http://scrippsco2.ucsd.edu/assets/data/atmospheric/stations/in_situ_co2/monthly/monthly_in_situ_co2_mlo.csv"
```
2. Remove the header of the file to retain only the data
3. Filter out missing data (`-99.99`)
4. Update the column names using the `colnames` vector below
```{r setup, message=F}
colnames=c("year","month","excel","decimal_year","co2","co2_seasonal","co2_fit","co2_seasonalfit","co2_filled","co2_seasonalfilled")
```
5. Calculate the mean $CO_2$ for each year from the `co2` column
6. plot a simple ggplot line graph of mean annual $CO_2$ concentration each year as shown below
```{r, purl=F, echo=F, message=F}
library(tidyverse)
httr::set_config(httr::config(ssl_verifypeer = 0L))
tf=tempfile()
httr::GET(data_url, httr::write_disk(tf, overwrite=TRUE))
read_csv(tf,
skip=57,
col_names=colnames,
na="-99.99") %>%
group_by(year) %>%
summarize(mean=mean(co2,na.rm=T)) %>%
ggplot(aes(x=year,y=mean))+
geom_line()
if(F){
library(tidyverse)
read_csv(data_url,
skip=57,
col_names=colnames,
na="-99.99") %>%
group_by(year) %>%
summarize(mean=mean(co2,na.rm=T)) %>%
ggplot(aes(x=year,y=mean))+
geom_line()
}
```