[R] NA's in multiple choice summary table in Hmisc

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Oct 10 00:44:07 CEST 2008


Erich Studerus wrote:
> Thank you so much. I have yet another problem that I could not resolve from
> the documentation. I want to get line breaks for long variable names.
> 
> Here's an example:
> Gender<-sample(c("m","f"),20,replace=TRUE)
> Education<-rnorm(20,13)
> label(Education)<-"Years of\nEducation"
> summary(Gender~Education,method="reverse")
> Descriptive Statistics by Gender
> 
> Descriptive Statistics by Gender
> 
> +---------+--------------+--------------+
> |         |f             |m             |
> |         |(N=12)        |(N=8)         |
> +---------+--------------+--------------+
> |Years of |12.5/12.9/13.9|12.5/12.9/13.5|
> |Education|              |              |
> +---------+--------------+--------------+
> 
> As you can see, it works fine for the printing in R, but when I submit this
> table to the latex-function the \n gets removed. How can I prevent this?
> 
> Regards
> Erich

That would take very special treatment in LaTeX; it's not that simple.
Frank

> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Frank E Harrell Jr [mailto:f.harrell at vanderbilt.edu] 
> Gesendet: Donnerstag, 9. Oktober 2008 04:17
> An: Erich Studerus, Psychiatrische Uni-Klinik
> Cc: r-help at r-project.org
> Betreff: Re: [R] NA's in multiple choice summary table in Hmisc
> 
> Erich Studerus, Psychiatrische Uni-Klinik wrote:
>> Hi,
>>
>> I have a set of 30 binary variables measuring side effects after drug 
>> treatment. Since each subject can have multiple side effects, I want to 
>> display these side effects in a multiple choice table. I'm using the 
>> summary and mChoice functions of the Hmisc package, because it produces 
>> nicely formatted latex tables. My problem is, that table includes a 
>> category for people who have at least one absent symptom and I don't 
>> know how to exclude it.
>>
>> Here's a very easy reproducible example:
>>
>> library(Hmisc)
>> Symptom1<-c("Headache","Headache",NA)
>> Symptom2<-c(NA,"Anxiety",NA)
>> Symptoms<-mChoice(Symptom1,Symptom2)
>> summary(~Symptoms,method="reverse")
>> Descriptive Statistics  (N=3)
>>
>> +-------------------+-------+
>> |                   |       |
>> +-------------------+-------+
>> |Symptom1 : Headache|67% (2)|
>> +-------------------+-------+
>> |    NA             |67% (2)|
>> +-------------------+-------+
>> |    Anxiety        |33% (1)|
>> +-------------------+-------+
>>
>> Now, I want to either completely exclude the NA category or - if 
>> included - it should count the number of people who have NA's in all 
>> symptoms rather than in a single symptom. In the example above, the NA's 
>> should be 1 instead of 2 cases.
>> I tried to specify na.include=FALSE but it does not work.
>>
>> Any help is highly appreciated.
>>
>> Erich
> 
> Instead of NA put '' or "" and it should work.
> Frank
> 
> 


-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list