2017-01-05 6 views
2

R生成のLaTexテーブルの1つのセルに2つのサマリー統計を持たせることはできますか?私はtablesパッケージを使用しています。カラムをmean (sd)と要約したいと思います。ここにrmarkdownの再現可能な例があります。R、LaTexのセルを組み合わせる

--- 
output: pdf_document 
--- 
```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = TRUE) 
library(tables) 
library(dplyr) 
``` 

```{r table, results='asis'} 
seed <- 1 
iris2 <- iris %>% mutate(Region = factor(sample(c('East', 'West', 'Central'), 150, replace = TRUE))) 
tabular((Species + 1) ~ (Region + 1) * Sepal.Length * (mean + sd), 
     data = iris2) %>% 
    latex %>% 
    print 
``` 

出力は次のようになります。LaTex Table

しかし、私は、細胞が、例えば次のようになりたいです5.037(0.3041)。それは可能ですか?

答えて

0

おそらく、例えば、あなたが(ペーストを使用したいもの)

paste(round(mean[1], digits=3), "(", sd[1], ")", collapse="") 
+0

表形式の呼び出しでどのように動作するのかわかりません –

0

貼り付け擬似関数は、トリックを行いますが、不要なパディングを紹介します(:Remove padding from pasted cells in LaTex, R参照)を行うことができます。例コード:

--- 
output: pdf_document 
--- 
```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = TRUE) 
library(tables) 
library(dplyr) 
``` 

```{r table, results='asis'} 
seed <- 1 
iris2 <- iris %>% mutate(Region = factor(sample(c('East', 'West', 'Central'), 150, replace = TRUE))) 
tabular((Species + 1) ~ (Region + 1) * Sepal.Length * Paste(Percent(), length, sep = '\\% (', postfix = ')'), 
     data = iris2) %>% 
    latex %>% 
    print 
```