I have perused several sites and watched a couple of videos on the package rempsyc ( an all of its affiliated packages) but I am having trouble incorporating the multilevel spanner. Has anyone used this before, or has some suggestions? I feel like it should be quite simple but i keep getting errors. I have the following packages installed:
library(dplyr)
library(forcats)
library(tidyverse)
library(rempsyc)
library(knitr)
library(flextable)
pr_counts<- table(as.character(court_data$ProsRace_coll))
# Calculate percentages
total_count <- sum(pr_counts)
pr_percentage_data <- data.frame(
Character_Type = names(pr_counts),
Count = as.numeric(pr_counts),
Percentage = (pr_counts / total_count) * 100
) %>%
select(Character_Type, Percentage.Freq)
total_count <- sum(pr_counts)
pr_percentage_data <- data.frame(
Race = c("Black/African American", "White", "Other"),
N = c(pr_counts[1], pr_counts[2], pr_counts[3]),
Percentage = c(pr_counts[1], pr_counts[2], pr_counts[3]) / total_count * 100
)
juv_counts <- table(as.character(court_data$JuvRace_coll))
total_juv_count <- sum(juv_counts)
juv_percentage_data <- data.frame(
N = c(juv_counts[1], juv_counts[2],juv_counts[3]),
Percentage = c(juv_counts[1], juv_counts[2], juv_counts[3]) / total_count * 100
)
def_counts <- table(as.character(court_data$DefRace_coll))
total_def_count <- sum(def_counts)
def_percentage_data <- data.frame(
N = c(def_counts[1], def_counts[2],def_counts[3]),
Percentage = c(def_counts[1], def_counts[2], def_counts[3]) / total_count * 100
)
combined_percentage_data <- data.frame(
Race = pr_percentage_data$Race,
Youth = juv_percentage_data$Percentage,
Defender = def_percentage_data$Percentage,
Prosecutor = pr_percentage_data$Percentage
)
testtable<- nice_table(combined_percentage_data)
testtable <- testtable %>%
split_header(col_keys = c("Youth", "Defender", "Prosecutor"), labels = "Hearing Level") %>%
merge_header(col_keys = "Race", label = "Personal Characteristics") %>%
autofit()
The last 5 lines of this code generates errors. This image shows how I want the table to be structured (sans judge level). I know there are probable several ways to do this and I just need one. Please help if you can. Much appreciated !