Summarise categorical data across columns

Hello team,

I am trying to summarise some categorical data and am struggling. Your help would be greatly appreciated!

I want to create summary statistics and (if possible graphs) for different combinations of the variables.
E.g. in the mock code bellow, how many participants said yes (Y) to both X, Y and Z vs just X...
There are a lot of columns in the real data set, so the less manual re-coding the better!
And any tips on visualisation would be awesome:)
I hope this is not to long a winded QU to ask. Iv been staying at the computer for a long time.

Thank you!!!

id <- c("A","B","C","D")

x <- sample(c("N","Y"), 4, replace = TRUE)

y <- sample(c("N","Y"), 4, replace = TRUE)

z <- sample(c("N","Y"), 4, replace = TRUE)

data.frame(id,x,y,z)
library(tidyverse)

id <- c("A","B","C","D")

x <- sample(c("N","Y"), 4, replace = TRUE)

y <- sample(c("N","Y"), 4, replace = TRUE)

z <- sample(c("N","Y"), 4, replace = TRUE)

test <- data.frame(id,x,y,z)
  
test |>
  mutate(
    across(-id, ~ .x == "Y"),
    x_y = x & y) |>
  summarise(across(-id, sum))
#>   x y z x_y
#> 1 1 0 1   0

Created on 2021-09-27 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.