-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatransform.R
35 lines (22 loc) · 931 Bytes
/
datatransform.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
data = read.csv("C:/users/konsta/desktop/vaestokoe/kuntainvaki.csv", header = TRUE, stringsAsFactors = FALSE, sep=",")
library(foreign)
alat = read.dbf("C:/users/konsta/desktop/vaestokoe/Kunnat2013eimerta.dbf")
str(alat)
alat$text = as.character(alat$text)
alat$text = substring(sapply(strsplit(alat$text,","),"[",1),4)
alat = alat[order(alat$text),]
colnames(data) = c("kunta", seq(1980,2012,1))
data$kunta = substring(sapply(strsplit(data$kunta,","),"[",1),4)
library(stringr)
data$kunta = str_replace_all(data$kunta, "ä", "ä")
data$kunta = str_replace_all(data$kunta, "Ä", "Ä")
data$kunta = str_replace_all(data$kunta, "ö", "ö")
data$kunta = str_replace_all(data$kunta, "Ã¥", "å")
tiheydet =data[,-1]/alat$ala
str(tiheydet)
data[,-1] = tiheydet
str(data)
library(reshape2)
rdat = melt(data, id.vars="kunta", variable.name="vuosi", value.name="tiheys")
rdat$vuosi = as.numeric(as.character(rdat$vuosi))
str(rdat)