Skip to content

Instantly share code, notes, and snippets.

@jamesdunham
Created July 18, 2018 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdunham/859bedc6dd283a24bc6746a859268548 to your computer and use it in GitHub Desktop.
Save jamesdunham/859bedc6dd283a24bc6746a859268548 to your computer and use it in GitHub Desktop.
# Define a minimal Ctrl object
Ctrl <- setClass("Ctrl", slots = c(item_data = "data.frame", item_names = "ANY",
time_name = "character", geo_name = "character", group_names = "ANY",
weight_name = "ANY", time_filter='numeric'))
# Create minimal test data
test_data = data.table(
abortion = c(0, 0, 1, 2),
year = 2018,
state = 'MA',
race3 = 1,
weight = 1)
# Instantiate a corresponding ctrl object
ctrl = Ctrl(item_data = opinion, item_names = 'abortion', time_name = 'year',
geo_name = 'state', group_names = 'race3', weight_name = 'weight',
time_filter = unique(test_data$year))
# First dichotomize
item_data <- dichotomize(test_data, ctrl)
# Then aggregate
make_group_counts(item_data, NULL, ctrl)[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment