-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 29.3 KB
/
.Rhistory
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
View(house_price_index)
View(gdp_per_capita)
View(house_price_index)
View(gdp_per_capita)
View(house_price_index)
house_price_index = read.csv("house_price_index.csv", sep=";")
house_price_index = read.csv("house_price_index.csv", sep=";")
View(house_price_index)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";")
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",chack_names = FALSE)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check_names = FALSE)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
View(house_price_index)
house_price_index = read.csv("house_price_index.csv", sep=";",check.names = FALSE)
View(house_price_index)
View(gdp_per_capita)
gdp_per_capita = read.csv("gdp_per_capita.csv", sep=",", nrows = 1,check.names = FALSE)
View(gdp_per_capita)
library(dplyr)
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
summarise(housing_loans_interest_rates, mean_int_rates = mean(housing_loans_interest_rates$`Loan type`))
View(housing_loans_interest_rates)
select(substr(colnames(housing_loans_interest_rates),0,2))
substr(colnames(housing_loans_interest_rates),0,2)
substr(colnames(housing_loans_interest_rates),3,7)
mutate(year = substr(colnames(housing_loans_interest_rates),3,7))
mutate(housing_loans_interest_rates, year = substr(colnames(housing_loans_interest_rates),3,7))
group_by(substr(colnames(housing_loans_interest_rates),3,7))
group_by(to_factor(substr(colnames(housing_loans_interest_rates),3,7)))
group_by(factor(substr(colnames(housing_loans_interest_rates),3,7)))
number(substr(colnames(housing_loans_interest_rates),3,6))
numeric(substr(colnames(housing_loans_interest_rates),3,6))
substr(colnames(housing_loans_interest_rates),3,6)
substr(colnames(housing_loans_interest_rates[-1]),3,6)
substr(colnames(housing_loans_interest_rates[-1]),4,6)
substr(colnames(housing_loans_interest_rates[-1]),4,5)
group_by(substr(colnames(housing_loans_interest_rates[-1]),4,5))
group_by(numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
substr(colnames(housing_loans_interest_rates[-1]),4,5)
numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
group_by(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
group_by(as.factor(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
mutate(housing_loans_interest_rates, year = substr(colnames(housing_loans_interest_rates[-1]),4,5)))
mutate(housing_loans_interest_rates, year = substr(colnames(housing_loans_interest_rates[-1]),4,5))
mutate(housing_loans_interest_rates, year = distinct(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
mutate(housing_loans_interest_rates, year = distinct(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
mutate(housing_loans_interest_rates, year = distinct(as.factor(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
mutate(housing_loans_interest_rates, year = distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
mutate(housing_loans_interest_rates, year = distinct(as.numeric(as.data.frame(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
mutate(housing_loans_interest_rates, year = as.numeric(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
mutate(housing_loans_interest_rates, year = as.numeric(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(substr(colnames(housing_loans_interest_rates),3,7))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(substr(colnames(housing_loans_interest_rates),3,7)))
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
mutate(housing_loans_interest_rates, year = distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
View(housing_loans_interest_rates)
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
select(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
select(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))) %>%
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
year = distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
View(year)
mutate(housing_loans_interest_rates, year = year)
year = distinct(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
year = as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
n_distinct(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
year = unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
mutate(housing_loans_interest_rates, year = year)
group_by(year) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
mutate(housing_loans_interest_rates, year = year)
housing_loans_interest_rates[year] <- NA
View(housing_loans_interest_rates)
housing_loans_interest_rates[year] <- NA
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
cbind(housing_loans_interest_rates, setNames( lapply(year, function(x) x=NA), year) )
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
View(house_price_index)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";")
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
library(dplyr)
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
select(year, mean_int_rates) %>%
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n()
mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
average(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(year,mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n(year))
group_by(year) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(distinct(as.data.frame(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))) %>%
summarise(year,n = n())
group_by(year) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
group_by(year)
year
group_by(year)
group_by_(year)
year =
unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
group_by(unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
group_by(housing_loans_interest_rates,unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))))
group_by(housing_loans_interest_rates)
View(housing_loans_interest_rates)
group_by(housing_loans_interest_rates[-1])
group_by(substr(colnames(housing_loans_interest_rates[-1]),4,5))
group_by(housing_loans_interest_rates[-1])
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
housing_loans_interest_rates[-1]
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
colnames(housing_loans_interest_rates[-1]
colnames(housing_loans_interest_rates[-1])
colnames(housing_loans_interest_rates[-1]) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
View(housing_loans_interest_rates)
housing_loans_interest_rates$colnames(housing_loans_interest_rates[-1]) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates[-1]) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
View(housing_loans_interest_rates)
names(housing_loans_interest_rates[-1])
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
group_by(year)
group_by(year) %>%
summarise(mean_int_rates = mean(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))),n = n())
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
housing_loans_interest_rates[-1]
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
View(housing_loans_interest_rates)
housing_loans_interest_rates[-1]
housing_loans_interest_rates[1]
housing_loans_interest_rates[1] <- 'Loan type'
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates[1])
names(housing_loans_interest_rates[0])
names(housing_loans_interest_rates[1]) <- 'Loan type'
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
names(housing_loans_interest_rates[1])
names(housing_loans_interest_rates[1]) <- "Loan type"
View(housing_loans_interest_rates)
names(housing_loans_interest_rates[1]) <- "Loan type1"
View(housing_loans_interest_rates)
names(housing_loans_interest_rates[1]) <- "Loan type"
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates)[1] <- "Loan type"
View(housing_loans_interest_rates)
group_by(year)
library(dplyr)
group_by(year)
summary(year)
summary()
group_by(housing_loans_interest_rates.)
unique(as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5)))
year
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean)
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
housing_loans_interest_rates[1]
housing_loans_interest_rates[1,1]
housing_loans_interest_rates[,1]
housing_loans_interest_rates
head(housing_loans_interest_rates,1)
housing_loans_interest_rates <- head(housing_loans_interest_rates,1)
housing_loans_interest_rates
View(housing_loans_interest_rates)
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
View(housing_loans_interest_rates)
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates)[1] <- "Loan type"
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(! is.na(x))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(! is.na(housing_loans_interest_rates))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(! is.na())))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(! is.na(1))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(!is.na(gl(1, 12)))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(!is.na(t))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean.default)))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean.default))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)[1]
names(housing_loans_interest_rates)[-1]
names(housing_loans_interest_rates)[ncol(housing_loans_interest_rates)]
housing_loans_interest_rates)[ncol(housing_loans_interest_rates)
housing_loans_interest_rates[ncol(housing_loans_interest_rates)]
rm(housing_loans_interest_rates[ncol(housing_loans_interest_rates)])
rm(names(housing_loans_interest_rates)[ncol(housing_loans_interest_rates)])
names(housing_loans_interest_rates)[-ncol(housing_loans_interest_rates)]
names(housing_loans_interest_rates) <- names(housing_loans_interest_rates)[-ncol(housing_loans_interest_rates)]
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
housing_loans_interest_rates <- head(housing_loans_interest_rates,1)
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates)[1] <- "Loan type"
housing_loans_interest_rates <- names(housing_loans_interest_rates)[-ncol(housing_loans_interest_rates)]
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
housing_loans_interest_rates <- head(housing_loans_interest_rates,1)
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates)[1] <- "Loan type"
names(housing_loans_interest_rates)[-ncol(housing_loans_interest_rates)]
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)[-ncol(housing_loans_interest_rates)]
housing_loans_interest_rates[-ncol(housing_loans_interest_rates)]
housing_loans_interest_rates <- housing_loans_interest_rates[-ncol(housing_loans_interest_rates)]
View(housing_loans_interest_rates)
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
View(housing_loans_interest_rates)
housing_loans_interest_rates <- head(housing_loans_interest_rates,1)
View(housing_loans_interest_rates)
as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)[1]
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)[1] <- "Loan type"
View(housing_loans_interest_rates)
housing_loans_interest_rates[-ncol(housing_loans_interest_rates)]
names(housing_loans_interest_rates[-ncol(housing_loans_interest_rates)])
names(housing_loans_interest_rates[ncol(housing_loans_interest_rates)])
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)
names(housing_loans_interest_rates[ncol(housing_loans_interest_rates)])
housing_loans_interest_rates[ncol(housing_loans_interest_rates)]
housing_loans_interest_rates[-ncol(housing_loans_interest_rates)]
View(housing_loans_interest_rates)
housing_loans_interest_rates[1:length(housing_loans_interest_rates)-1]
names(housing_loans_interest_rates[1:length(housing_loans_interest_rates)-1])
housing_loans_interest_rates[1:length(housing_loans_interest_rates)]
housing_loans_interest_rates[1:(length(housing_loans_interest_rates)-1)]
housing_loans_interest_rates[1:(length(housing_loans_interest_rates))]
length(housing_loans_interest_rates)
View(housing_loans_interest_rates)
names(housing_loans_interest_rates[ncol(housing_loans_interest_rates)])
names(housing_loans_interest_rates[ncol(housing_loans_interest_rates)]) <- "20"
View(housing_loans_interest_rates)
names(housing_loans_interest_rates)[ncol(housing_loans_interest_rates)] <- "20"
View(housing_loans_interest_rates)
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
tapply(housing_loans_interest_rates, gl(1,12), mean)
tapply(housing_loans_interest_rates, gl(2,12), mean)
mean(housing_loans_interest_rates, gl(1,12))
aggregate(housing_loans_interest_rates,list(rep(1:(nrow(housing_loans_interest_rates)%/%12+1),each=12,len=nrow(housing_loans_interest_rates))),mean)[-1]
warnings()
View(housing_loans_interest_rates)
summary(housing_loans_interest_rates)
str(housing_loans_interest_rates)
as.numeric(colnames(housing_loans_interest_rates[-1]))
as.numeric(housing_loans_interest_rates[-1])
as.double(housing_loans_interest_rates[-1])
double(housing_loans_interest_rates[-1]
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
housing_loans_interest_rates[-1]
sapply(housing_loans_interest_rates,as.double)
sapply(as.character(housing_loans_interest_rates),as.double)
View(housing_loans_interest_rates)
as.double(as.character(housing_loans_interest_rates))
View(housing_loans_interest_rates)
as.character(housing_loans_interest_rates)
View(housing_loans_interest_rates)
housing_loans_interest_rates
housing_loans_interest_rates[1]
as.character(housing_loans_interest_rates)
lapply(housing_loans_interest_rates, as.character)
housing_loans_interest_rates[]
housing_loans_interest_rates[] <- lapply(housing_loans_interest_rates, as.character)
View(housing_loans_interest_rates)
housing_loans_interest_rates[] <- lapply(housing_loans_interest_rates, as.double)
warnings()
)
warnings()
View(housing_loans_interest_rates)
housing_loans_interest_rates = read.csv("housing_loans_interest_rates.csv", sep=";",check.names = FALSE)
housing_loans_interest_rates <- head(housing_loans_interest_rates,1)
names(housing_loans_interest_rates) <- as.numeric(substr(colnames(housing_loans_interest_rates[-1]),4,5))
names(housing_loans_interest_rates)[1] <- "Loan type"
names(housing_loans_interest_rates)[ncol(housing_loans_interest_rates)] <- "20"
View(housing_loans_interest_rates)
lapply(housing_loans_interest_rates, as.character)
as.double(lapply(housing_loans_interest_rates, as.character))
View(housing_loans_interest_rates)
gsub(",",".",housing_loans_interest_rates)
View(housing_loans_interest_rates)
gsub(",",".",housing_loans_interest_rates[])
View(housing_loans_interest_rates)
sub(",",".",housing_loans_interest_rates)
as.double(gsub(",",".",housing_loans_interest_rates))
View(house_price_index)
View(housing_loans_interest_rates)
aggregate(housing_loans_interest_rates,list(rep(1:(nrow(housing_loans_interest_rates)%/%12+1),each=12,len=nrow(housing_loans_interest_rates))),mean)[-1]
list(rep(1:(nrow(housing_loans_interest_rates)%/%12+1),each=12,len=nrow(housing_loans_interest_rates)))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
View(housing_loans_interest_rates)
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(housing_loans_interest_rates,na.rm = TRUE)))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(!is.na(housing_loans_interest_rates[]))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(!is.na(housing_loans_interest_rates[]))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean(!is.na(housing_loans_interest_rates))))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean)))
t(apply(housing_loans_interest_rates, 1, tapply, gl(1, 12), mean))
View(housing_loans_interest_rates)
housing_loans_interest_rates(1:12)
housing_loans_interest_rates[1:12]
housing_loans_interest_rates[2:12]
View(housing_loans_interest_rates)
mean(housing_loans_interest_rates[2:12])
housing_loans_interest_rates[2:12]
View(housing_loans_interest_rates)
gsub(",",".",housing_loans_interest_rates)
as.double(gsub(",",".",housing_loans_interest_rates))
lapply(as.double(gsub(",",".",housing_loans_interest_rates)))
summary(housing_loans_interest_rates)
str(housing_loans_interest_rates)
as.character(housing_loans_interest_rates)
as.character(housing_loans_interest_rates[])
as.character(housing_loans_interest_rates[])
lapply(housing_loans_interest_rates, as.character)
View(housing_loans_interest_rates)
as.character(housing_loans_interest_rates[])
str(housing_loans_interest_rates)
housing_loans_interest_rates <- lapply(housing_loans_interest_rates, as.character)
View(housing_loans_interest_rates)
as.double(housing_loans_interest_rates)
View(housing_loans_interest_rates)
gsub(",",".",housing_loans_interest_rates)
View(housing_loans_interest_rates)
housing_loans_interest_rates <- gsub(",",".",housing_loans_interest_rates)
as.double(housing_loans_interest_rates)
str(housing_loans_interest_rates)
housing_loans_interest_rates <- lapply(housing_loans_interest_rates, as.double)
View(housing_loans_interest_rates)
View(housing_loans_interest_rates)
mean(housing_loans_interest_rates[2:12])
housing_loans_interest_rates[2:12]
str(housing_loans_interest_rates)
housing_loans_interest_rates[2:12]
mean(housing_loans_interest_rates[2:12])
lapply(housing_loans_interest_rates, mean, na.rm = TRUE)
lapply(housing_loans_interest_rates[2:12], mean, na.rm = TRUE)
lapply(results, mean, na.rm = TRUE)
lapply(housing_loans_interest_rates[2:12], mean, na.rm = TRUE)
colMeans(housing_loans_interest_rates[2:12])
colMeans(housing_loans_interest_rates[2:12])
sapply(colMeans(housing_loans_interest_rates))
sapply(colMeans(housing_loans_interest_rates),mean)
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
library(ggplot2)
library(ggplot2)
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
# Data source:
# https://databank.worldbank.org/reports.aspx?source=2&series=NY.GDP.PCAP.CD#
# https://www.hnb.hr/en/web/guest/statistics/statistical-data/financial-sector/other-monetary-financial-institutions/credit-institutions/interest-rates
# Data preprocessing
#gdp_per_capita in US$
gdp_per_capita = read.csv("gdp_per_capita.csv", sep=";", nrows = 1,check.names = FALSE)
house_price_index = read.csv("house_price_index.csv", sep=";", dec = ".", check.names = FALSE)
#1
housing_loans_interest_rates = read.csv("housing_loans_interest_rates_2.csv", sep=";",check.names = FALSE)
library(dplyr)
gdp_per_capita <- gdp_per_capita[4:ncol(gdp_per_capita)] %>%
select(starts_with("Series Name"),starts_with("201"))
house_price_index <- house_price_index[7:ncol(house_price_index)]
# we will take only housing loans (first row) - next analysis - some other housing loan rate type
#2
housing_loans_interest_rates <- head(housing_loans_interest_rates,1) %>%
select(starts_with("Loan"), starts_with("201", ignore.case = TRUE))
housing_loans_interest_rates <- sapply(housing_loans_interest_rates, gsub, pattern = ",", replacement= ".")
# transpose the datasets
gdp_per_capita_1 <- as.data.frame(matrix(gdp_per_capita))
rownames(gdp_per_capita_1) <- colnames(gdp_per_capita)
house_price_index_1 <- as.data.frame(matrix(house_price_index))
rownames(house_price_index_1) <- colnames(house_price_index)
housing_loans_interest_rates_1 <- as.data.frame(matrix(tail(housing_loans_interest_rates,-1)))
rownames(housing_loans_interest_rates_1) <- colnames(housing_loans_interest_rates)
# edit names of the columns
colnames(gdp_per_capita) <- "gdp_per_capita (us$)"
colnames(house_price_index) <- "house_price_index"
colnames(housing_loans_interest_rates) <- "housing_loans_interest_rates"
# edit names of the rows
rownames(housing_loans_interest_rates_1) <- c("2013","2014","2015","2016","2017","2018","2019")
# Binding datasets by rows
housing_loans_interest_rates_1 <- tail(housing_loans_interest_rates_1,-2)
dataset <- bind_cols(bind_cols(gdp_per_capita_1, house_price_index_1),housing_loans_interest_rates_1)
rownames(dataset) <- c("2015","2016","2017","2018","2019")
colnames(dataset) <- c("gdp_per_capita (us$)","house_price_index","housing_loans_interest_rates")
dataset$`gdp_per_capita (us$)` <- as.numeric(as.character(dataset$`gdp_per_capita (us$)`))
dataset$house_price_index <- as.numeric(as.character(dataset$house_price_index))
dataset$housing_loans_interest_rates <- as.numeric(as.character(dataset$housing_loans_interest_rates))
# Dependent variable - house price index
# Splitting the dataset into the Training set and Test set
library(caTools)
set.seed(123)
split = sample.split(dataset$`gdp_per_capita (us$)`, SplitRatio = 0.7)
training_set = subset(dataset, split == TRUE)
test_set = subset(dataset, split == FALSE)
# Feature Scaling - not needed in Multiple Linear Regression
#training_set = scale(training_set)
#test_set = scale(test_set)
# Fitting Multiple Linear Regressor to the training set
regressor = lm(house_price_index ~ .,
data = training_set)
# Predicting the test set results
y_pred = predict(regressor,
newdata = test_set)
# Backward elimination
# Visualizing the dataset - house price index,gdp per capita and interest rates per year
library(ggplot2)
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
# House price index isn't linear but polynomial -> using polynomial regression
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red')
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_point(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_line(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
ggplot() +
geom_point(aes(x = row.names(dataset), y = scale(dataset$house_price_index)),
color = 'red') +
geom_point(aes(x = row.names(dataset), y = scale(dataset$housing_loans_interest_rates), group = 1),
color = 'blue') +
geom_point(aes(x = row.names(dataset), y = scale(dataset$`gdp_per_capita (us$)`), group = 1),
color = 'dark green')
regressor
summary(regressor)
regressor = lm(house_price_index ~ .,
data = training_set)
summary(regressor)
regressor = lm(formula = house_price_index ~ `gdp_per_capita (us$)` + housing_loans_interest_rates,
data = dataset)
summary(regressor)
View(dataset)