IN r,如何将摘要结合在一起

发布于 2024-08-29 09:55:34 字数 874 浏览 1 评论 0原文

假设我有 5 组数据的 5 个摘要。我怎样才能得到这些数字或将摘要合并为 1 而不是 5

       V1               V2               V3               V4        
 Min.   : 670.2   Min.   : 682.3   Min.   : 690.7   Min.   : 637.6  
 1st Qu.: 739.9   1st Qu.: 737.2   1st Qu.: 707.7   1st Qu.: 690.7  
 Median : 838.6   Median : 798.6   Median : 748.3   Median : 748.3  
 Mean   : 886.7   Mean   : 871.0   Mean   : 869.6   Mean   : 865.4  
 3rd Qu.:1076.8   3rd Qu.:1027.6   3rd Qu.:1070.0   3rd Qu.: 960.8  
 Max.   :1107.8   Max.   :1109.3   Max.   :1131.3   Max.   :1289.6  
       V5        
 Min.   : 637.6  
 1st Qu.: 690.7  
 Median : 748.3  
 Mean   : 924.3  
 3rd Qu.: 960.8  
 Max.   :1584.3  

我怎样才能有 1 个表格看起来像

        v1  v2 v3 v4 v5
  Min.   :   
 1st Qu.:   
 Median : 
 Mean   :   
 3rd Qu.:   
 Max.   :  

或者如何将这些数字保存为向量,以便我可以使用矩阵生成表格

say i have 5 summary for 5 sets of data. how can i get those number out or combine the summary in to 1 rather than 5

       V1               V2               V3               V4        
 Min.   : 670.2   Min.   : 682.3   Min.   : 690.7   Min.   : 637.6  
 1st Qu.: 739.9   1st Qu.: 737.2   1st Qu.: 707.7   1st Qu.: 690.7  
 Median : 838.6   Median : 798.6   Median : 748.3   Median : 748.3  
 Mean   : 886.7   Mean   : 871.0   Mean   : 869.6   Mean   : 865.4  
 3rd Qu.:1076.8   3rd Qu.:1027.6   3rd Qu.:1070.0   3rd Qu.: 960.8  
 Max.   :1107.8   Max.   :1109.3   Max.   :1131.3   Max.   :1289.6  
       V5        
 Min.   : 637.6  
 1st Qu.: 690.7  
 Median : 748.3  
 Mean   : 924.3  
 3rd Qu.: 960.8  
 Max.   :1584.3  

how can i have 1 table looks like

        v1  v2 v3 v4 v5
  Min.   :   
 1st Qu.:   
 Median : 
 Mean   :   
 3rd Qu.:   
 Max.   :  

or how to save those number as vector so i can use matrix to generate a table

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与君绝 2024-09-05 09:55:34

看起来您的数据位于数据框或矩阵中。如果是这样,您可以执行以下操作:

> 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

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
破晓 2024-09-05 09:55:34

您可以将摘要输出转换为矩阵,然后绑定它们:

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

或者,您可以将它们组合成一个列表并使用 apply 函数(或 plyr):

library(plyr)
ldply(list(a, b, c), summary)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文