Rからレポート品質テーブルを作成するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/1407680

質問

resultという次のデータフレームがある場合

> result
     Name       CV      LCB       UCB
1  within 2.768443 1.869964  5.303702
2 between 4.733483 2.123816 18.551051
3   total 5.483625 3.590745 18.772389

> dput(result,"")
structure(list(Name = structure(c("within", "between", "total"
), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 
4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 
18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB"
), row.names = c(NA, 3L), class = "data.frame")

このデータをうまく表示する最良の方法は何ですか?理想的には、レポートに貼り付けることができる画像ファイル、または表を表すHTMLファイルが必要ですか?

有効数字の数を設定するための追加ポイント。

役に立ちましたか?

解決

xtable を使用します。通常、Sweaveで使用します。

library(xtable)
d <- data.frame(letter=LETTERS, index=rnorm(52)) 
d.table <- xtable(d[1:5,])
print(d.table,type="html")

Sweaveドキュメントで使用する場合は、次のように使用します。

<<label=tab1,echo=FALSE,results=tex>>=
xtable(d, caption = "Here is my caption", label = "tab:one",caption.placement = "top")
@

他のヒント

テーブルアスペクトについては、 xtable パッケージが付属していますLaTeX出力(Sweave経由でプロのレポートに使用できます)およびhtmlを生成できるため、注意してください。

Sweaveでそれを派手なグラフと組み合わせた場合(ggplotの例については他の質問を参照)、ほとんどそこにいます。

library(ggplot2)
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_errorbar() + geom_point()
ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_pointrange()

きれいなテーブルの作成についてコメントすることはできませんが、有効数字を設定するために最も簡単なのは(このサンプルデータの場合、Nameをrownamesに移動して全体を丸めることです)。

#Set the rownames equal to Name - assuming all unique
rownames(result) <- result$Name  
#Drop the Name column so that round() can coerce
#result.mat to a matrix
result.mat <- result[ , -1]       
round(result.mat, 2) #Where 2 = however many sig digits you want.            

これはひどく堅牢なソリューションではありません-一意でないName値は、他の非数値列と同様に、それを壊すと思います。しかし、あなたの例のようなテーブルを作成するためには、トリックを行います。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top