IN r, how to combine the summary together

别来无恙 提交于 2019-12-03 14:40:53

It looks like your data is in a data frame or matrix. If so, you can do the following:

> df <- data.frame(a=1:50, b=3:52, c=rnorm(500))
> apply(df, 2, summary)
           a    b         c
Min.     1.0  3.0 -3.724000
1st Qu. 13.0 15.0 -0.733000
Median  25.5 27.5 -0.004868
Mean    25.5 27.5 -0.033950
3rd Qu. 38.0 40.0  0.580800
Max.    50.0 52.0  2.844000

You can convert the summary output into a matrix and then bind them:

a <- 1:50
b <- 3:53 
c <- rnorm(500)
cbind(as.matrix(summary(a)), as.matrix(summary(b)), as.matrix(summary(c)))

Alternatively, you can combine them into a list and use an apply function (or plyr):

library(plyr)
ldply(list(a, b, c), summary)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!