-
Notifications
You must be signed in to change notification settings - Fork 17
/
combine-data.R
53 lines (46 loc) · 1.08 KB
/
combine-data.R
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
melb_df <- read.table(
file = "melbourne.csv",
header = TRUE,
sep = ",",
skip = 11)
mean_rainfall_melb <- as.numeric(melb_df[24,2:13])
ox_df <- read.table(
file = "oxford.txt",
header = FALSE,
col.names = c("year", "month", "x1", "x2", "x3", "rain", "x4"),
skip = 7,
na.strings = "---",
nrows = 12 * (2020 - 1853))
year_mask <- (1855 <= ox_df$year) & (ox_df$year <= 2015)
tmp <- ox_df[year_mask,c("month","rain")]
tmp$rain <- as.numeric(
gsub(
pattern = "\\*",
replacement = "",
x = tmp$rain))
mean_rainfall_ox <- aggregate(
x = tmp,
by = list(month = tmp$month),
FUN = mean)$rain
months <- c(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December")
plot_df <- data.frame(
month = rep(months, 2),
month_num = rep(1:12, 2),
location = rep(c("Melbourne", "Oxford"), each = 12),
average_rainfall = c(mean_rainfall_melb, mean_rainfall_ox))
write.table(x = plot_df,
file = "average-rainfall.csv",
sep = ",",
row.names = FALSE)