frcode: Recodes Variables and Keeps Factor Levels

Description Usage Arguments Examples

View source: R/frcode.R

Description

This a Modification of case_when that keeps things in the order they were recoded

Usage

1

Arguments

df

Name of the Dataset

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
cces <- read_csv("https://raw.githubusercontent.com/ryanburge/cces/master/CCES%20for%20Methods/small_cces.csv")

cces %>% 
    mutate(pid_new = frcode(pid7 == 1 ~ "Strong Democrat", 
                            pid7 == 2 ~ "Not Strong Democrat", 
                            pid7 == 3 ~ "Lean Democrat", 
                            pid7 == 4 ~ "Independent", 
                            pid7 == 5 ~ "Lean Republican", 
                            pid7 == 6 ~ "Not Strong Republican", 
                            pid7 == 7 ~ "Strong Republican", 
                            TRUE ~ "REMOVE")) %>% 
           ct(pid_new) %>% 
           filter(pid_new != "REMOVE") %>% 
           ggplot(., aes(x = pid_new, y = pct)) +
           geom_col()
  

ryanburge/socsci documentation built on June 6, 2020, 2:37 a.m.