-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloadHELPdata.R
36 lines (31 loc) · 951 Bytes
/
loadHELPdata.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
# =====================================
#
# loading the HELP dataset with formatting
# and lebeling - the codebook has been
# applied - see helpmkh.*
#
# dated 09/25/2018
# Melinda Higgins, PhD.
#
# =====================================
library(tidyverse)
library(haven)
help.spss <- haven::read_spss("helpmkh.sav")
# the "labelled" variables with "codebook"
# come in as a "labelled" class
# with attributes which include labels
attributes(help.spss$female)
class(help.spss$female)
table(help.spss$female)
# to see/use the labels, you can "coerce"
# these labelled variables into factors
# using the as_factor() function in haven
table(as_factor(help.spss$female))
plot(as_factor(help.spss$female),
main="Frequencies of Gender")
# racegrp is a character variable
# which works fine for table
# but still need as_factor() for plot
table(help.spss$racegrp)
plot(as_factor(help.spss$racegrp),
main = attributes(help.spss$racegrp)$label)