本文介绍了如何扩展“摘要"功能以包括 sd、峰度和偏斜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R 的 summary
函数在数据帧上工作得非常好,例如:
R's summary
function works really well on a dataframe, giving, for example:
> summary(fred)
sum.count count sum value
Min. : 1.000 Min. : 1.0 Min. : 1 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 6.0 1st Qu.: 7 1st Qu.:35.82
Median : 1.067 Median : 9.0 Median : 10 Median :42.17
Mean : 1.238 Mean : 497.1 Mean : 6120 Mean :43.44
3rd Qu.: 1.200 3rd Qu.: 35.0 3rd Qu.: 40 3rd Qu.:51.31
Max. :40.687 Max. :64425.0 Max. :2621278 Max. :75.95
我想要做的是修改函数,以便在均值"之后给出标准差、峰态和偏斜的条目.
What I'd like to do is modify the function so it also gives, after 'Mean', an entry for the standard deviation, the kurtosis and the skew.
这样做的最佳方法是什么?我对此进行了一些研究,添加带有方法的函数对我不起作用:
What's the best way to do this? I've researched this a bit, and adding a function with a method doesn't work for me:
> summary.class <- function(x)
{
return(sd(x))
}
上面的只是被忽略了.我想我需要了解如何定义所有要返回的类.
The above is just ignored. I suppose that I need to understand how to define all classes to return.
推荐答案
如何使用 psych
包中已有的解决方案?
How about using already existing solutions from the psych
package?
my.dat <- cbind(norm = rnorm(100), pois = rpois(n = 100, 10))
library(psych)
describe(my.dat)
# vars n mean sd median trimmed mad min max range skew kurtosis se
# norm 1 100 -0.02 0.98 -0.09 -0.06 0.86 -3.25 2.81 6.06 0.13 0.74 0.10
# pois 2 100 9.91 3.30 10.00 9.95 4.45 3.00 17.00 14.00 -0.07 -0.75 0.33
这篇关于如何扩展“摘要"功能以包括 sd、峰度和偏斜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!