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

From: Kwok, Heemun <hkwok_at_emedharbor.edu>
Date: Sat, 26 Mar 2011 23:09:57 -0700

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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 27 Mar 2011 - 07:50:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 27 Mar 2011 - 18:10:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive