2
如何從Hmisc中彙總輸出,並以正確的格式將其呈現在knitr中,並且最好以合作伙伴的表格的形式傳輸給Word?R markdown v2和Hmisc表格
以下塊生成一個表,但是格式化關閉(所有的值標籤和號碼的變量在同一行,而不是下對方)
---
output: word_document
---
```{r table, results='asis'}
library(Hmisc)
options(digits=3)
set.seed(173)
sex <- factor(sample(c("m","f"), 500, rep=TRUE))
age <- rnorm(500, 50, 5)
treatment <- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))
# Generate a 3-choice variable; each of 3 variables has 5 possible levels
symp <- c('Headache','Stomach Ache','Hangnail',
'Muscle Ache','Depressed')
symptom1 <- sample(symp, 500,TRUE)
symptom2 <- sample(symp, 500,TRUE)
symptom3 <- sample(symp, 500,TRUE)
Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms')
table(Symptoms)
# Note: In this example, some subjects have the same symptom checked
# multiple times; in practice these redundant selections would be NAs
# mChoice will ignore these redundant selections
#Frequency table sex*treatment, sex*Symptoms
summary(sex ~ treatment + Symptoms, fun=table)
```
不是一個簡單的問題...好像[Gmisc :: HTMLTABLE(http://gforge.se/gmisc /)可以幫助,另一個例子[這裏](http://timelyportfolio.blogspot.com/2013/04/tables-are-like-cockroaches.html) – Ben