-1

我无法获得具有Hmisc::latexsapply功能的表格。latex返回许多表。我想使用 aHmisc::latex因为它更灵活的可配置性。

重现问题的步骤:

library(xtable)
library(Hmisc)
library(nortest)
set.seed(1)
x <- matrix(rnorm(10*100), nrow=100)
norm.x <- sapply(x, sf.test)[1:2,]
latex(norm.x, file="", dec=2)
xtable(norm.x) # In contrast xtable produce pretty output

编辑:

解决方案(感谢 Sven Hohenstein):

library(Hmisc)
library(nortest)
set.seed(1)
x <- matrix(rnorm(10*100), nrow=100)
norm.x <- sapply(x, function(z) unlist(sf.test(z)[c("statistic", "p.value")]))
latex(norm.x, file="", dec=2)
4

1 回答 1

1

您可以使用函数和修改norm.x返回的对象。sapply(x, sf.test)[1:2,]unlistmatrix

norm.x <- matrix(unlist(norm.x), nrow = 2, dimnames = list(c("w", "p-value")))

完整代码:

library("xtable")
library("Hmisc")
library("nortest")
set.seed(1)
x <- data.frame(replicate(10, rnorm(100)))
norm.x <- sapply(x, sf.test)[1:2,]
norm.x <- matrix(unlist(norm.x), nrow = 2, dimnames = list(c("w", "p-value")))
latex(norm.x, file="", dec=2)
xtable(norm.x)
于 2012-12-03T13:53:22.250 回答