# Install Packages
if(!require(dplyr)) {install.packages("sjlabelled", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(sjlabelled)) {install.packages("sjlabelled", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(sjmisc)) {install.packages("sjmisc", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(sjstats)) {install.packages("sjstats", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(sjPlot)) {install.packages("sjlabelled", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(summarytools)) {install.packages("summarytools", repos='https://cran.csiro.au/', dependencies=TRUE)}
if(!require(ggplot2)) {install.packages("ggplot2", repos='https://cran.csiro.au/', dependencies= TRUE)}
if(!require(ggthemes)) {install.packages("ggthemes", repos='https://cran.csiro.au/', dependencies= TRUE)}
# Load packages into memory
library(dplyr)
library(sjlabelled)
library(sjmisc)
library(sjstats)
library(sjPlot)
library(summarytools)
library(ggplot2)
library(ggthemes)
# Turn off scientific notation
options(digits=5, scipen=15)
# Stop View from overloading memory with a large datasets
RStudioView <- View
View <- function(x) {
if ("data.frame" %in% class(x)) { RStudioView(x[1:500,]) } else { RStudioView(x) }
}
elect_2013 <- read.csv(url("https://methods101.com/data/elect_2013.csv"))
frq(elect_2013, country_birth)
##
## country_birth <integer>
## # total N=3955 valid N=3795 mean=2.65 sd=3.52
##
## val frq raw.prc valid.prc cum.prc
## 1 2819 71.28 74.28 74.28
## 2 70 1.77 1.84 76.13
## 3 307 7.76 8.09 84.22
## 4 10 0.25 0.26 84.48
## 5 51 1.29 1.34 85.82
## 6 27 0.68 0.71 86.53
## 7 17 0.43 0.45 86.98
## 8 39 0.99 1.03 88.01
## 9 26 0.66 0.69 88.70
## 10 28 0.71 0.74 89.43
## 11 26 0.66 0.69 90.12
## 12 375 9.48 9.88 100.00
## <NA> 160 4.05 NA NA
elect_2013$d_aust <- elect_2013$country_birth
elect_2013$d_nz <- elect_2013$country_birth
elect_2013$d_uk <- elect_2013$country_birth
elect_2013$d_ireland <- elect_2013$country_birth
elect_2013 <- rec(elect_2013, d_aust, rec = "1=1; NA=NA; else=0", append = TRUE, suffix = "")
elect_2013 <- rec(elect_2013, d_nz, rec = "2=1; NA=NA; else=0", append = TRUE, suffix = "")
elect_2013 <- rec(elect_2013, d_uk, rec = "3=1; NA=NA; else=0", append = TRUE, suffix = "")
elect_2013 <- rec(elect_2013, d_ireland, rec = "4=1; NA=NA; else=0", append = TRUE, suffix = "")
frq(elect_2013, d_aust)
##
## d_aust <numeric>
## # total N=3955 valid N=3795 mean=0.74 sd=0.44
##
## val frq raw.prc valid.prc cum.prc
## 0 976 24.68 25.72 25.72
## 1 2819 71.28 74.28 100.00
## <NA> 160 4.05 NA NA
frq(elect_2013, d_ireland)
##
## d_ireland <numeric>
## # total N=3955 valid N=3795 mean=0.00 sd=0.05
##
## val frq raw.prc valid.prc cum.prc
## 0 3785 95.70 99.74 99.74
## 1 10 0.25 0.26 100.00
## <NA> 160 4.05 NA NA
|