-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_hyvinvointi.R
80 lines (63 loc) · 2.19 KB
/
data_hyvinvointi.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
## ------------------------------------ ##
## Datan käsittelyä ##
## ------------------------------------ ##
load("data/ess_hyvinvointi.rda")
df <- ess_hyvinvointi
library(plyr)
relevel_likert5 <- function(x) {
x <- revalue(x, c("Agree strongly"=5,
"Agree"=4,
"Neither agree nor disagree"=3,
"Disagree"=2,
"Disagree strongly"=1))
x <- as.character(x)
x[x %in% "Refusal"] <- NA
x[x %in% "Don't know"] <- NA
x[x %in% "No answer"] <- NA
x <- factor(x, levels=c("5","4","3","2","1"))
}
df$dngval <- relevel_likert5(df$dngval)
df$nhpftr <- relevel_likert5(df$nhpftr)
df$lotsgot <- relevel_likert5(df$lotsgot)
df$lfwrs <- relevel_likert5(df$lfwrs)
df$flclpla <- relevel_likert5(df$flclpla)
## påalvelujärjestelm'
df$stfedu <- revalue(df$stfedu, c("Extremely bad"="0",
"Extremely good"="10"))
df$stfhlth <- revalue(df$stfhlth, c("Extremely bad"="0",
"Extremely good"="10"))
# onnellinen
df$happy <- revalue(df$happy, c("Extremely unhappy"="0",
"Extremely happy"="10"))
# terveys
relevel_health <- function(x) {
x <- revalue(x, c("Very good"=5,
"Good"=4,
"Fair"=3,
"Bad"=2,
"Very bad"=1))
x <- as.character(x)
x[x %in% "Refusal"] <- NA
x[x %in% "Don't know"] <- NA
x[x %in% "No answer"] <- NA
x <- factor(x, levels=c("5","4","3","2","1"))
}
df$health <- relevel_health(df$health)
relevel_satisfied <- function(x) {
revalue(x, c("Extremely dissatisfied"="0",
"Extremely satisfied"="10"))
}
df$stflife <- relevel_satisfied(df$stflife)
df$stfeco <- relevel_satisfied(df$stfeco)
df$stfgov <- relevel_satisfied(df$stfgov)
df$stfdem <- relevel_satisfied(df$stfdem)
# # luottamus-muuttujat
# df$trstprl <- relevel_trust(df$trstprl)
# df$trstlgl <- relevel_trust(df$trstlgl)
# df$trstplc <- relevel_trust(df$trstplc)
# df$trstplt <- relevel_trust(df$trstplt)
# df$trstprt <- relevel_trust(df$trstprt)
# df$trstep <- relevel_trust(df$trstep)
# df$trstun <- relevel_trust(df$trstun)
# # ladataan graafifunktio
#