I am having a hard time doing this efficiently and apologize if it's a basic question. I need to make a contingency table with N and percent to summarize relationships between a large number of binary variables, simply in terms of freq and percent, with no other summary statistics.
Specifically, it is to summarize the number of patients that have sample type X and clinical outcome Y. A patient can have any number of outcomes and any number of samples, i.e. each variable is non-mutually exclusive and independent.
I would like to put all the outcomes (Death, ICU admission, leg fell off...) as columns, and all the sample types (serum, urine, etc...) as rows. I would only need to list the frequency and percentage of "positive" responses, i.e. N and % of patients who died and who had a urine sample.
Are there any packages out there that could help with this kind of table? Everything I am finding is good for doing a nice 1xN variable contingency table. I wouldn't mind making a separate table for each outcome, if I can somehow extract a column of that output and bind them together into a master table to rule them all. Another idea is to somehow make a frequency table of two mChoice (Hmisc package) variables. I do not know if either of those two strategies are possible.
Any ideas?
What I'm looking for is something like this:
+-------------+--------+---------+
| | Death | ICU |
| | (N=10) | (N=50) |
+-------------+--------+---------+
|Serum (N=50) |5 (50%) | 30 (60%)|
+-------------+--------+---------+
|Urine (N=40) |10(100%)| 7 (14%) |
+-------------+--------+---------+
|Brain (N=25) |6 (60%) | 15 (30%)|
+-------------+--------+---------+
|Kidney (N=50)|7 (70%) | 40 (80%)|
+-------------+--------+---------+
Edit to include sample data:
set.seed(1)
death<-runif(1000)<=.75
ICU<-runif(1000)<=.63
serum<-runif(1000)<=.80
urine<-runif(1000)<=.77
brain<-runif(1000)<=.92
kidney<-runif(1000)<=.22
df<-as.data.frame(cbind((1:1000),death,ICU,serum,urine,brain,kidney))