ct: An All-Purpose Count Function

Description Usage Arguments Examples

View source: R/ct.R

Description

This function gives you a simple count with percentages that is weighted

Usage

1
ct(df, var, wt, cum = FALSE, show_na = TRUE)

Arguments

df

Name of the Dataset

var

Variable to Count

wt

Weighting Variable

cum

Will add a cumulative total if set to TRUE

show_na

Will remove the NAs before the calculation if set to TRUE, defaults to FALSE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cces <- read_csv("https://raw.githubusercontent.com/ryanburge/blocks/master/cces.csv")
cces %>% 
   ct(race)
   
# With a weight 
cces %>% 
     ct(race, wt = commonweight_vv)            
     
cces %>% 
   mutate(race2 = frcode(race == 1 ~ "White",
                     race == 2 ~ "Black", 
                     race == 3 ~ "Hispanic",
                      race == 4 ~ "Asian")) %>% 
  ct(race2, show_na = FALSE, commonweight_vv)   
     
# Cumulative Counts       

cces %>% 
     ct(race, cum = TRUE)

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