This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathnaomitague.Rmd
143 lines (98 loc) · 2.12 KB
/
naomitague.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
title: "ntague"
author: "Naomi Tague"
date: "January 15, 2016"
output:
html_document:
theme: united
highlight: tango
toc: true
toc_depth: 2
---
## Content
Provide some information on art, environment

## Techniques
Key techniques for visualization
## Data
Data for visualization
Here is some data from [Water data](http://waterdata.usgs.gov/nwis/rt):
```{r}
pcp = read.table('data/pcp.txt', header=T)
summary(pcp)
library(lubridate)
pcp$dater = mdy(pcp$date)
pcp$month = months(pcp$dater)
pcp$year = year(pcp$dater)
pcp$day = day(pcp$dater)
small = pcp %>% select(month:day)
tmp = gather(pcp, "year","n", c(4:6))
```
## Data Wrangling
```{r, eval=FALSE}
# present working directory
getwd()
# change working directory
setwd('.')
# list files
list.files()
# list files that end in '.jpg'
list.files(pattern=glob2rx('*.jpg'))
# file exists
file.exists('test.png')
```
# Install Packages
```{r, eval=FALSE}
# Run this chunk only once in your Console
# Do not evaluate when knitting Rmarkdown
# list of packages
```
## utils::read.csv
Traditionally, you would read a CSV like so:
```{r}
d = read.csv('../data/r-ecology/species.csv')
d
head(d)
summary(d)
```
## readr::read_csv
Better yet, try read_csv:
```{r}
library(readr)
d = read_csv('../data/r-ecology/species.csv')
d
head(d)
summary(d)
```
## dplry::tbl_df
Now convert to a dplyr table:
```{r}
library(readr)
library(dplyr)
d = read_csv('../data/r-ecology/species.csv')
d = tbl_df(d)
d = read_csv('../data/r-ecology/species.csv') %>%
tbl_df()
d = tbl_df(read_csv('../data/r-ecology/species.csv'))
head(d)
summary(d)
glimpse(d)
```
## dplyr loosely
### What year does species 'NL' show up in the surveys.csv?
```{r}
library(readr)
library(dplyr)
read_csv('../data/r-ecology/surveys.csv') %>%
select(species_id, year) %>%
#filter(species_id == 'NL') %>%
group_by(species_id, year) %>%
summarize(count = n())
d = read_csv('../data/r-ecology/species.csv') %>%
tbl_df()
d = tbl_df(read_csv('../data/r-ecology/species.csv'))
d
head(d)
summary(d)
glimpse(d)
```