-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
102 lines (75 loc) · 3.88 KB
/
README.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
---
title: "Lab 1"
author: "Group 12"
date: "2/4/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(RCurl)
```
## GitHub Respository
Our GitHub repository for this lab is https://github.com/sreinGIT/STAT585-Lab1.git.
## Build a Book
The last word in chapter 15 is pseudo-class.
The biggest problem that we encountered was an error that occured when the index.Rmd file tried to compile line 783 of Conditions.Rmd. The error was
> Execution halted Error in Rscript_render(f, render_args, render_meta) : Failed to compile Conditions.Rmd Calls: <Anonymous> ... render_book -> render_new_session -> Rscript_render Execution halted
We tried Googling the error but were unable to find helpful fixes. In the end, we added "error = TRUE" to the header of that code chunk so that the file would continue to compile despite the error.
## Weather Station
```{r, include=FALSE}
# Download the file ushcn-v2.5-stations.txt from the FTP site ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5:
# Url of FTP site and name of file to download
URL <- "ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn-v2.5-stations.txt"
# Name of file. If no folder is specified, the file will be saved in the working directory.
destfile <- "ushcn-v2.5-stations.txt"
download.file(URL, destfile)
```
```{r, include=FALSE}
# Read the weather data
weather <- read_fwf("ushcn-v2.5-stations.txt",
col_positions = fwf_positions(start = c(1, 3, 4, 6, 13, 22, 33, 39, 42, 73, 80, 87, 94), end = c(2, 3, 5, 11, 20, 30, 37, 40, 71, 78, 85, 92, 95), col_names = c("COUNTRY CODE", "NETWORK CODE ", "ID PLACEHOLDERS", "COOP ID", "LATITUDE", "LONGITUDE", "ELEVATION", "STATE", "NAME", "COMPONENT 1", "COMPONENT 2", "COMPONENT 3", "UTC OFFSET")))
weather <- weather %>%
mutate(ELEVATION = as.numeric(ELEVATION))
usa <- map_data("state")
statename <- data.frame(STATE = state.abb, region = tolower(state.name), stringsAsFactors = FALSE)
usa <- usa %>%
left_join(statename, by = "region") %>%
left_join(unique(weather[c("STATE", "UTC OFFSET")]), by = "STATE")
```
```{r echo=FALSE}
theme_set(theme_light())
weather %>%
ggplot(aes(x = LONGITUDE, y = LATITUDE, fill = `UTC OFFSET`)) +
geom_polygon(data = usa, aes(x = long, y = lat, group = group)) +
geom_path(data = usa, aes(x = long, y = lat, group = group), alpha = 0.3) +
geom_point(aes(colour = ELEVATION)) +
scale_fill_gradient(low = "pink", high = "yellow") +
ggtitle("Stations, Elevation and Time Zone") +
theme(plot.title = element_text(hjust = 0.5, face = "bold", size = 20))
# Some states have two "UTC OFFSET" values, so the time zone may not be exactly true
```
## More Weather Data
```{r, include=FALSE}
# Url of FTP site and name of gz file to download
URL <- "ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tavg.latest.raw.tar.gz"
# Name of gz file. If no folder is specified, the file will be saved in the working directory.
destfile <- "ushcn.tavg.latest.raw.tar.gz"
download.file(URL, destfile)
```
```{r, echo=FALSE}
# Create a folder called TavgLatestRaw. The gz file will be unzipped in this folder.
TavgLatestRawFolder <- "TavgLatestRaw"
dir.create(TavgLatestRawFolder, showWarnings=FALSE)
# Unzip the gz file. This will create a folder "ushcn something-something" within the TavgLatestRaw folder. This newest folder will contains the unzipped files.
untar("ushcn.tavg.latest.raw.tar.gz", exdir=TavgLatestRawFolder)
# Get the name of the new folder "ushcn something-something"
UnzippedFolder <- list.files(TavgLatestRawFolder)
# Change the working directory to the folder TavgLatestRaw
setwd(TavgLatestRawFolder)
# read file names of the unzipped files in "ushcn something-something"
files <-dir(UnzippedFolder)
# count the number of files
numfiles <- length(files)
```
The file ushcn.tavg.latest.raw.tar.gz downloaded from ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5 contains `r numfiles` files.