【发布时间】:2016-05-09 00:07:38
【问题描述】:
尝试使用来自rockchalk 包的summarize 输出汇总统计信息。
希望统计数据四舍五入到小数点后两位。我收到一条错误消息
在summarize 上使用round。
library(rockchalk)
M1 <- structure(c(0.18, 0.2, 0.24, 0.35, -0.22, -0.17, 0.28, -0.28, -0.14, 0.03, 0.87, -0.2, 0.06, -0.1, -0.72, 0.18, 0.01, 0.31, -0.36, 0.61, -0.16, -0.07, -0.13, 0.01, -0.09, 0.26, -0.14, 0.08, -0.62, -0.2, 0.3, -0.21, -0.11, 0.05, 0.06, -0.28, -0.27, 0.17, 0.42, -0.05, -0.15, 0.05, -0.07, -0.22, -0.34, 0.16, 0.34, 0.1, -0.12, 0.24, 0.45, 0.37, 0.61, 0.9, -0.25, 0.02), .Dim = c(56L, 1L))
#This works
round(apply(M1, 2, mean),2)
#This works
summaryround <- function(x) {round(summary(x),2)}
apply(M1, 2, summaryround)
#This gives error "non-numeric argument"
round(apply(M1, 2, summarize),2)
#Thought this would work but also gives error "non-numeric argument"
summarizeround <- function(x) {round(summarize(x),2)}
apply(M1, 2, summarizeround)
有什么想法吗?我可以将summary 的输出四舍五入,但想使用summarize
如果可能的话,我想在同一个打印输出中获得峰度和偏度的输出(当然,可以创建我自己的函数,结合 summary 和 kurtosis 以及我想要的任何东西,而不是如果可以避免的话)。
编辑:应该提到在大型数据帧上实际运行它;将其转换为 1 列矩阵,因为我认为这会使可重现的示例更简单。
【问题讨论】: