-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask1.Rmd
More file actions
79 lines (61 loc) · 1.98 KB
/
Task1.Rmd
File metadata and controls
79 lines (61 loc) · 1.98 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
title: "Task 1. Exploring Stream Flow"
author: "John Fay"
date: " Fall 2019"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Overview
1. Prepping your workspace for analysis
2. Getting the data into the R workspace
3. Tidying the data
4. Exploratory data analysis
5. Comparing streamflow before and after Falls Lake dam constuction
# 1. Prepping your workspace for analysis
```{r Installing and loading libraries}
#Install the tidyverse package onto your machine
install.packages('tidyverse')
#Load the tidyverse package into this session
library(tidyverse)
```
# 2. Getting the data into R with `rvest`
* See https://readr.tidyverse.org/reference/read_delim.html for more information
```{r Get the data}
#Get the URL
url = 'http://waterservices.usgs.gov/nwis/dv/?format=rdb&sites=02087500&startDT=1930-10-01&endDT=2017-09-30&statCd=00003¶meterCd=00060&siteStatus=all'
#Read the data (tab separated) into a dataframe, skipping metadata lines, and assigning column names
theData <- read_tsv(file = url,
skip=30,
col_names = c('agency_cd','site_no','datetime','MeanFlow_cfs','Confidence'),
)
#Display the data (first 5 rows)
head(theData)
#Display the column names
colnames(theData)
#Display the structure of the dataframe
str(theData)
#Display the dimensions of the dataframe
dim(theData)
#Display the first 10 records of a single column of data
theData$MeanFlow_cfs[1:10]
#Display a summary of the data
summary(theData)
#Display summary of one data column
summary(theData$MeanFlow_cfs)
```
# 3. Tidy the data:
* Set the datetime column as a date-time column type
```{r set date}
theData$datetime2 <- as.Date(theData$datetime,format = "%y-%m-%d")
str(theData)
```
* Add a column for water flow in CMS
```{r calccms}
#Create cms column to plot cubic meters per second
theData$Flow_cms <- neuse$Flow*0.028316847
summary(neuse$Flow_cms)
```