[R] Hmisc summary.formula formats for binary and continuous variables

Kwok, Heemun hkwok at emedharbor.edu
Sun Mar 27 08:09:57 CEST 2011


Hello,
I am using Hmisc summary.formula, latex and Sweave to produce tables for publication.  Is it possible to change the formats for binary and continuous variables?  I would prefer to show 35 (10%) and 1.5 (1.2-1.8) rather than 10% (35) and 1.2 / 1.5 / 1.8. Here is a simple example:

sex <- factor(sample(c("m","f"), 500, rep=TRUE))
age <- rnorm(500, 50, 5)
treatment <- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))

s1 <- summary(~sex + age)
s2 <- summary(treatment ~ sex + age, method="reverse")
print(s1); print(s2)

Descriptive Statistics  (N=500)

+-------+-----------------+
|       |                 |
+-------+-----------------+
|sex : m|    46% (232)    |
+-------+-----------------+
|age    |47.22/50.31/53.37|
+-------+-----------------+



Descriptive Statistics by treatment

+-------+-----------------+-----------------+
|       |Drug             |Placebo          |
|       |(N=257)          |(N=243)          |
+-------+-----------------+-----------------+
|sex : m|    47% (122)    |    45% (110)    |
+-------+-----------------+-----------------+
|age    |47.35/50.00/52.68|46.78/50.92/53.97|
+-------+-----------------+-----------------+

Thanks,
Heemun


-------------------------------------------------
Heemun Kwok, M.D.
Research Fellow
Harbor-UCLA Department of Emergency Medicine
1000 West Carson Street, Box 21
Torrance, CA 90509-2910
office 310-222-3501, fax 310-212-6101



More information about the R-help mailing list