forked from oscarperpinan/spacetime-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataTime.R
109 lines (81 loc) · 3.73 KB
/
dataTime.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
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
##################################################################
## Source code for the book: "Displaying time series, spatial and
## space-time data with R"
## Copyright (C) 2012 Oscar Perpiñán Lamigueiro
## This program is free software you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; either version 2 of the License,
## or (at your option) any later version.
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.
####################################################################
##################################################################
## SIAR
##################################################################
##################################################################
## Daily data of different meteorological variables
##################################################################
library(zoo)
aranjuez <- read.zoo("data/aranjuez.gz",
index.column = 3, format = "%d/%m/%Y",
fileEncoding = 'UTF-16LE',
header = TRUE, fill = TRUE,
sep = ';', dec = ",", as.is = TRUE)
aranjuez <- aranjuez[, -c(1:4)]
names(aranjuez) <- c('TempAvg', 'TempMax', 'TempMin',
'HumidAvg', 'HumidMax',
'WindAvg', 'WindMax',
'Radiation', 'Rain', 'ET')
summary(aranjuez)
aranjuezClean <- within(as.data.frame(aranjuez),{
TempMin[TempMin>40] <- NA
HumidMax[HumidMax>100] <- NA
WindAvg[WindAvg>10] <- NA
WindMax[WindMax>10] <- NA
})
aranjuez <- zoo(aranjuezClean, index(aranjuez))
save(aranjuez, file='data/aranjuez.RData')
##################################################################
## Solar radiation measurements from different locations
##################################################################
##################################################################
## Unemployment in the United States
##################################################################
unemployUSA <- read.csv('data/unemployUSA.csv')
nms <- unemployUSA$Series.ID
##columns of annual summaries
annualCols <- 14 + 13*(0:12)
## Transpose. Remove annual summaries
unemployUSA <- as.data.frame(t(unemployUSA[,-c(1, annualCols)]))
## First 7 characters can be suppressed
names(unemployUSA) <- substring(nms, 7)
head(unemployUSA)
library(zoo)
Sys.setlocale("LC_TIME", 'C')
idx <- as.yearmon(row.names(unemployUSA), format='%b.%Y')
unemployUSA <- zoo(unemployUSA, idx)
isNA <- apply(is.na(unemployUSA), 1, any)
unemployUSA <- unemployUSA[!isNA,]
save(unemployUSA, file='data/unemployUSA.RData')
##################################################################
## Gross National Income and $CO_2$ emissions
##################################################################
library(WDI)
CO2data <- WDI(indicator=c('EN.ATM.CO2E.PC', 'EN.ATM.CO2E.PP.GD',
'NY.GNP.MKTP.PP.CD', 'NY.GNP.PCAP.PP.CD'),
start=2000, end=2011,
country=c('BR', 'CN', 'DE', 'ES',
'FI', 'FR', 'GR', 'IN', 'NO', 'US'))
names(CO2data) <- c('iso2c', 'Country.Name', 'Year',
'CO2.capita', 'CO2.PPP',
'GNI.PPP', 'GNI.capita')
isNA <- apply(is.na(CO2data), 1, any)
CO2data <- CO2data[!isNA, ]
CO2data$Country.Name <- factor(CO2data$Country.Name)
save(CO2data, file='data/CO2.RData')