I have a similar dataset:
val<-c("Y","N")
test<-data.frame(age=rnorm(n=100,mean=50,sd=10),var1=sample(val,100,T),var2=sample(val,100,T),var3=sample(val,100,T),sex=sample(c("F","M"),100,T))
I´d like to create a summary reporting the mean age for each category using Hmisc.
library(Hmisc)
summary.formula(age~sex+var1+var2+var3,data=test)
However, var1-var3 actually belong under the same categorical variable with levels var1,var and var3 instead of Y/N. Furthermore, these are not mutually exclusive. So, is it possible somehow to create a variable var4 with these different levels that are not mutually exclusive and type
summary.formula(age~sex+var4,data=test)
and have an output like:
+-------+-+---+----+
| | |N |age |
+-------+-+---+----+
|sex |F| 44|48.0|
| |M| 56|50.8|
+-------+-+---+----+
|var4 |var1| xx|yy|
| |var2| xx|yy|
|var3| xx|yy|
+-------+-+---+----+
|Overall| |100|49.6|
+-------+-+---+----+
Any help would be much appreciated...