forked from ucsb-bren/ESM296-3W-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjupa1089.Rmd
179 lines (135 loc) · 2.88 KB
/
jupa1089.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: "jupa1089 Details"
author: "Julia P."
date: "January 17, 2016"
output:
html_document:
toc: true
toc_depth: 2
---
## Content
Does citizen monitoring (via **SMS surveys**) impact the quality of municipal waste collection services in *Kampala, Uganda*?
[link](https://github.com/citizen-monitoring/citizen-monitoring.github.io)

## Techniques
The most applicable techniques:
* data organization,
+ calculating summary statistics,
+ clear, shareable code.
## Data
We have preliminary survey result data from Mark Buntaine. These are in excel format and will have any identifying information removed.
```{r}
#read csv
d = read.csv('data/jupa1089_ugandaSMS.csv')
#output summary
summary(d)
```
##Data Wrangling
```{r, eval=FALSE}
#present working directory
getwd()
#change working directory
setwd('C:/Users/paltsev/Documents/gitsnorlax/env-info')
#list files
list.files()
#list files that end in '.jpg'
list.files(pattern=glob2rx('*.jpg'))
#file exists
file.exists('test.png')
setwd('students')
```
###Install Packages
```{r, eval=FALSE}
#run this chunk only once in your Console
#do not evaluate when knitting Rmarkdown
#list of packages
pkgs = c(
'readr',
'readxl',
'dplyr',
'tidyr',
'nycflights13',
'gapminder')
#install packages if not found
for (p in pkgs){
if (!require(p, character.only=T)){
install.packages(p)
}
}
```
###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
head(d)
summary(d)
glimpse(d)
```
###dplry loosely
####What year does species "NL" show up in survey.csv?
```{r}
library(readr)
library(dplyr)
read_csv('../data/r-ecology/surveys.csv') %>%
select(species_id, year) %>%
#filter(species_id == 'NL') %>%
group_by(year) %>%
summarize(count = n())
d = read_csv('../data/r-ecology/surveys.csv') %>%
tbl_df()
d
head(d)
summary(d)
glimpse(d)
```
##Wrangling Webinar
```{r}
#View(iris)
#iris %>%
#select(Species, Petal.Length)
#install.packages("devtools")
#devtools::install_github("rstudio/EDAWR")
#library(EDAWR)
#View(storms)
#View(cases)
#View(pollution)
#storms$storm
#storms$wind
#storms$pressure
#storms$date
#cases$country
#names(cases)[-1]
#unlist(cases[1:3, 2:4])
#pollution$amount[1:5]
#storms$pressure / storms$wind
#library(tidyr)
#?gather
#?spread
#gather(cases, "year", "n", 2:4)
#spread(pollution, size, amount)
#storms2 <- separate(storms, date, c("year", "month", "day"), sep = "-")
#unite(storms2, "date", year, month, day, sep = "-")
```