My input data has 3 columns - stent_type, success, stent_30. stent_type is either a category 0 or 1, success is either a 0 or 1, and stent_30 is either a 0 or 1 (basically was the stent placed before or after 30 days). I would like to create a 2x3 table with the percent/number of successfully placed stents for category 0 or 1 stents, along with a p-value comparing the two columns for stent_30. Something like this:
| Stent < 30 | Stent > 30 | p-value | |
|---|---|---|---|
| stent 0 | 75%(10) | 70% (9) | 0.1 |
| stent 1 | 50% (6) | 40% (2) | 0.05 |
I'm basically having trouble because I'm not sure how to summarize a category based on 2 different categories (if that makes sense?)
Sample input data here:
structure(list(success = c(1, 1, 1, 1, 1), stent_type = c(1,
1, 1, 0, 1), stent_30 = c(TRUE, TRUE, FALSE, FALSE, TRUE)), row.names = c(NA,
5L), class = "data.frame")
With credit to the answer from BigMistake here.