-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatted_tenure_by_housing_costs.R
100 lines (74 loc) · 4.27 KB
/
formatted_tenure_by_housing_costs.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
#dataframes for 2010
tenurebyhousingcosts2010 = t(data.frame(estimate(benchmarks2010[[3]])))
#dataframes for 2011
tenurebyhousingcosts2011 = t(data.frame(estimate(benchmarks2011[[3]])))
#dataframes for 2012
tenurebyhousingcosts2012 = t(data.frame(estimate(benchmarks2012[[3]])))
#dataframes for 2013
tenurebyhousingcosts2013 = t(data.frame(estimate(benchmarks2013[[3]])))
#dataframes for 2014
tenurebyhousingcosts2014 = t(data.frame(estimate(benchmarks2014[[3]])))
#combine all into one list
tenurebyhousingcosts <- list("2010" = tenurebyhousingcosts2010,
"2011" = tenurebyhousingcosts2011,
"2012" = tenurebyhousingcosts2012,
"2013" = tenurebyhousingcosts2013,
"2014" = tenurebyhousingcosts2014)
# transform data to include years in first columns
write.csv(tenurebyhousingcosts$`2010`, file = "tenurebyhousingcosts2010.csv")
tenurebyhousingcosts2010 <- data.frame(read.csv("tenurebyhousingcosts2010.csv"))
headers <- colnames(tenurebyhousingcosts2010)
headers[1] <- "Measures"
colnames(tenurebyhousingcosts2010) <-headers
tenurebyhousingcosts2010$year<-"2010"
lengthofcolumns <-length(colnames(tenurebyhousingcosts2010))
tenurebyhousingcosts2010<-tenurebyhousingcosts2010[c(lengthofcolumns,1:lengthofcolumns-1)]
write.csv(tenurebyhousingcosts$`2011`, file = "tenurebyhousingcosts2011.csv")
tenurebyhousingcosts2011 <- data.frame(read.csv("tenurebyhousingcosts2011.csv"))
headers <- colnames(tenurebyhousingcosts2011)
headers[1] <- "Measures"
colnames(tenurebyhousingcosts2011) <-headers
tenurebyhousingcosts2011$year<-"2011"
lengthofcolumns <-length(colnames(tenurebyhousingcosts2011))
tenurebyhousingcosts2011<-tenurebyhousingcosts2011[c(lengthofcolumns,1:lengthofcolumns-1)]
write.csv(tenurebyhousingcosts$`2012`, file = "tenurebyhousingcosts2012.csv")
tenurebyhousingcosts2012 <- data.frame(read.csv("tenurebyhousingcosts2012.csv"))
headers <- colnames(tenurebyhousingcosts2012)
headers[1] <- "Measures"
colnames(tenurebyhousingcosts2012) <-headers
tenurebyhousingcosts2012$year<-"2012"
lengthofcolumns <-length(colnames(tenurebyhousingcosts2012))
tenurebyhousingcosts2012<-tenurebyhousingcosts2012[c(lengthofcolumns,1:lengthofcolumns-1)]
write.csv(tenurebyhousingcosts$`2013`, file = "tenurebyhousingcosts2013.csv")
tenurebyhousingcosts2013 <- data.frame(read.csv("tenurebyhousingcosts2013.csv"))
headers <- colnames(tenurebyhousingcosts2013)
headers[1] <- "Measures"
colnames(tenurebyhousingcosts2013) <-headers
tenurebyhousingcosts2013$year<-"2013"
lengthofcolumns <-length(colnames(tenurebyhousingcosts2013))
tenurebyhousingcosts2013<-tenurebyhousingcosts2013[c(lengthofcolumns,1:lengthofcolumns-1)]
write.csv(tenurebyhousingcosts$`2014`, file = "tenurebyhousingcosts2014.csv")
tenurebyhousingcosts2014 <- data.frame(read.csv("tenurebyhousingcosts2014.csv"))
headers <- colnames(tenurebyhousingcosts2014)
headers[1] <- "Measures"
colnames(tenurebyhousingcosts2014) <-headers
tenurebyhousingcosts2014$year<-"2014"
lengthofcolumns <-length(colnames(tenurebyhousingcosts2014))
tenurebyhousingcosts2014<-tenurebyhousingcosts2014[c(lengthofcolumns,1:lengthofcolumns-1)]
#remove intermediate csv files
file.remove("tenurebyhousingcosts2010.csv",
"tenurebyhousingcosts2011.csv",
"tenurebyhousingcosts2012.csv",
"tenurebyhousingcosts2013.csv",
"tenurebyhousingcosts2014.csv")
#recombine
tenurebyhousingcosts <- list("2010" = tenurebyhousingcosts2010,
"2011" = tenurebyhousingcosts2011,
"2012" = tenurebyhousingcosts2012,
"2013" = tenurebyhousingcosts2013,
"2014" = tenurebyhousingcosts2014)
#write out data into csv
#write.table(tenurebyhousingcosts$`2010`, file = "tenurebyhousingcosts.csv", append = TRUE, row.names = FALSE, sep = ",")
#write.table(tenurebyhousingcosts$`2011`, file = "tenurebyhousingcosts.csv", append = TRUE, row.names = FALSE, sep = ",", col.names = FALSE)
#write.table(tenurebyhousingcosts$`2012`, file = "tenurebyhousingcosts.csv", append = TRUE, row.names = FALSE, sep = ",", col.names = FALSE)
#write.table(tenurebyhousingcosts$`2013`, file = "tenurebyhousingcosts.csv", append = TRUE, row.names = FALSE, sep = ",", col.names = FALSE)