library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Import Data

library(ggplot2)
Voter_Data_2019 <- read_csv("Downloads/Voter Data 2019.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double(),
##   weight_18_24_2018 = col_logical(),
##   izip_2019 = col_character(),
##   housevote_other_2019 = col_character(),
##   senatevote_other_2019 = col_character(),
##   senatevote2_other_2019 = col_character(),
##   SenCand1Name_2019 = col_character(),
##   SenCand1Party_2019 = col_character(),
##   SenCand2Name_2019 = col_character(),
##   SenCand2Party_2019 = col_character(),
##   SenCand3Name_2019 = col_character(),
##   SenCand3Party_2019 = col_character(),
##   SenCand1Name2_2019 = col_character(),
##   SenCand1Party2_2019 = col_character(),
##   SenCand2Name2_2019 = col_character(),
##   SenCand2Party2_2019 = col_character(),
##   SenCand3Name2_2019 = col_character(),
##   SenCand3Party2_2019 = col_character(),
##   governorvote_other_2019 = col_character(),
##   GovCand1Name_2019 = col_character(),
##   GovCand1Party_2019 = col_character()
##   # ... with 108 more columns
## )
## ℹ Use `spec()` for the full column specifications.
## Warning: 800 parsing failures.
##  row               col           expected           actual                            file
## 2033 weight_18_24_2018 1/0/T/F/TRUE/FALSE .917710168467982 'Downloads/Voter Data 2019.csv'
## 2828 weight_18_24_2018 1/0/T/F/TRUE/FALSE 1.41022291345592 'Downloads/Voter Data 2019.csv'
## 4511 weight_18_24_2018 1/0/T/F/TRUE/FALSE 1.77501243840922 'Downloads/Voter Data 2019.csv'
## 7264 weight_18_24_2018 1/0/T/F/TRUE/FALSE 1.29486870319614 'Downloads/Voter Data 2019.csv'
## 7277 weight_18_24_2018 1/0/T/F/TRUE/FALSE 1.44972719707603 'Downloads/Voter Data 2019.csv'
## .... ................. .................. ................ ...............................
## See problems(...) for more details.
Voter_Data_2019 <- Voter_Data_2019%>%select(partyreg_baseline, econtrend_2018, third_econ_2018, ft_immig_2017)
head(Voter_Data_2019)
## # A tibble: 6 x 4
##   partyreg_baseline econtrend_2018 third_econ_2018 ft_immig_2017
##               <dbl>          <dbl>           <dbl>         <dbl>
## 1                 9              2               2            95
## 2                 2              1               4            96
## 3                 9              3               1            77
## 4                 4             NA              NA            NA
## 5                 9              1               4            91
## 6                 1              3               1           100

Recode Variables

Voter_Data_2019 <- Voter_Data_2019%>%mutate(EconomyChanging = ifelse(econtrend_2018==1,"Getting Better",
                                        ifelse(econtrend_2018==2,"About the Same",
                                        ifelse(econtrend_2018==3,"Getting Worse",NA))),
  Thirdpartyinvolveeconomicissues = ifelse(third_econ_2018==1, "More liberal than the Democratic
 Party", 
                       ifelse(third_econ_2018==2,"About where the Democratic Party
 is now",
                       ifelse(third_econ_2018==8, "In between the Democratic Party
 and the Republican Part", NA))),
  Party= ifelse(partyreg_baseline==1, "Democrat",
                 ifelse(partyreg_baseline==2,"Republican",NA)),
  FeelingAboutImmigrants = ifelse(ft_immig_2017>100,NA,ft_immig_2017))

head(Voter_Data_2019)
## # A tibble: 6 x 8
##   partyreg_baseli… econtrend_2018 third_econ_2018 ft_immig_2017 EconomyChanging
##              <dbl>          <dbl>           <dbl>         <dbl> <chr>          
## 1                9              2               2            95 About the Same 
## 2                2              1               4            96 Getting Better 
## 3                9              3               1            77 Getting Worse  
## 4                4             NA              NA            NA <NA>           
## 5                9              1               4            91 Getting Better 
## 6                1              3               1           100 Getting Worse  
## # … with 3 more variables: Thirdpartyinvolveeconomicissues <chr>, Party <chr>,
## #   FeelingAboutImmigrants <dbl>

Preview Filtered New Variables

head(Voter_Data_2019%>%select(Party, EconomyChanging, Thirdpartyinvolveeconomicissues, FeelingAboutImmigrants)%>%
  group_by(Party))
## # A tibble: 6 x 4
## # Groups:   Party [3]
##   Party     EconomyChanging Thirdpartyinvolveeconomicissues  FeelingAboutImmigr…
##   <chr>     <chr>           <chr>                                          <dbl>
## 1 <NA>      About the Same  "About where the Democratic Par…                  95
## 2 Republic… Getting Better   <NA>                                             96
## 3 <NA>      Getting Worse   "More liberal than the Democrat…                  77
## 4 <NA>      <NA>             <NA>                                             NA
## 5 <NA>      Getting Better   <NA>                                             91
## 6 Democrat  Getting Worse   "More liberal than the Democrat…                 100