I have a data set that looks like this:
ID wts S2 S5.1 S5.2 S5.3
42 0.78 Male Yes No Yes
45 1.22 Female No Yes No
48 0.98 Male Yes Yes Yes
49 1.11 Female Yes Yes No
51 1.21 Male Yes Yes No
I am trying to create a weighted table using the 'crosstab' function in the 'descr' package. I've got a basic table working properly with the following line:
crosstab(*fileName*$S5.1,*fileName*$S2,weight=wts,prop.c=T)
But what I really want to do is have all 3 of the binary variables down the y-axis of the table. I've looked around for days and cannot figure it out. Any help would be appreciated! I am pulling data in through an SPSS file if that info. helps.
Apologies if this is a very simple question. Very new to R.
dput(head(data))
structure(list(ID = c(42, 45, 48, 49, 51), wts = c(0.78, 1.22,
0.98, 1.11, 1.21), S2 = structure(c(1L, 2L, 1L, 2L, 1L), .Label = c("Male",
"Female"), class = "factor"), S5.1 = structure(c(2L, 1L, 2L,
2L, 2L), .Label = c("No", "Yes"), class = "factor"), S5.2 = structure(c(1L,
2L, 2L, 2L, 2L), .Label = c("No", "Yes"), class = "factor"),
S5.3 = structure(c(2L, 1L, 2L, 1L, 1L), .Label = c("No",
"Yes"), class = "factor")), .Names = c("ID", "wts", "S2",
"S5.1", "S5.2", "S5.3"), variable.labels = structure(c("", "",
"Gender", "Dog?", "Cat?", "Bird?"), .Names = c("ID", "wts", "S2",
"S5.1", "S5.2", "S5.3")), codepage = 1252L, row.names = c(NA,
5L), class = "data.frame")
I was hoping for something resembling this... (where the 2nd and 3rd Yes/No's added are S5.2 and S5.3, respectively). thanks!
==========================================
temp.spss$S2
temp.spss$S5.1 Male Female Total
------------------------------------------
No 0 1 1
0.000 50.000
------------------------------------------
Yes 3 1 4
100.000 50.000
------------------------------------------
No 1 0 1
33.333 00.000
------------------------------------------
Yes 2 2 4
66.666 100.000
------------------------------------------
No 1 2 3
33.333 100.000
------------------------------------------
Yes 2 0 2
66.666 0.000
------------------------------------------
Total 9 6 15
180.000 120.000
==========================================