1

psych::cortest.mat を使用して相関行列の比較を作成しました。出力を Sweave ファイルに入れ、knitr で制作したいと考えています。Hmisc::latex() 関数を使用すると機能しますが、結果ごとに約 7 桁の数字が生成されるため、非常に魅力的ではありません。Knitr 内でマークアップ引数を使用して出力を生成することもできますが、ドキュメント内の他のすべてのテーブルは、ラテックス出力 (results='asis') を使用してより効率的に生成されます。

考え?

#Sample data
variable1<-rnorm(100, mean=7, sd=1)
variable2<-rnorm(100, mean=4, sd=1)
variable3<-rnorm(100, mean=6, sd=1)
variable4<-rnorm(100, mean=8, sd=2)
variable5<-rnorm(100, mean=9, sd=1)
variable6<-rnorm(100, mean=7, sd=3)
#Correlation matrices
cor.mat1<-cor(data.frame(variable1, variable2, variable3))
cor.mat2<-cor(data.frame(variable4, variable5, variable6))
library(psych)
library(Hmisc)
#Compare matrices
cor.comparison<-cortest.mat(cor.mat1, cor.mat2, n1=100, n2=100)
#try to print
latex(cor.comparison, file='')
#try unclassing
test<-unclass(cor.comparison)
#Try with lapply
lapply(test, function(x) round(x,2))
#try also changing options(digits=)
options(digits=3)
latex(cor.comparison, file='')
4

1 に答える 1