码迷,mamicode.com
首页 > 其他好文 > 详细

Restructure output of R summary function

时间:2018-06-30 11:04:53      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:com   overflow   cti   values   put   nbsp   structure   amp   rest   


 Treat it as a data.frame:

set.seed(1)
x <- sample(30, 100, TRUE)

summary(x)
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
#    1.00   10.00   15.00   16.03   23.25   30.00
summary(data.frame(x))
#        x        
#  Min.   : 1.00  
#  1st Qu.:10.00  
#  Median :15.00  
#  Mean   :16.03  
#  3rd Qu.:23.25  
#  Max.   :30.00

For slightly more usable output, you can use data.frame(unclass(.)):
val = data.frame(unclass(summary(x)))
val
#           val
# Min.     1.00
# 1st Qu. 10.00
# Median  15.00
# Mean    16.03
# 3rd Qu. 23.25
# Max.    30.00

val[1,1]
val[2,1]
val[3,1]

Or you can use stack:

stack(summary(x))
#   values     ind
# 1   1.00    Min.
# 2  10.00 1st Qu.
# 3  15.00  Median
# 4  16.03    Mean
# 5  23.25 3rd Qu.
# 6  30.00    Max.

Ref:

https://stackoverflow.com/questions/27715934/restructure-output-of-r-summary-function

Restructure output of R summary function

标签:com   overflow   cti   values   put   nbsp   structure   amp   rest   

原文地址:https://www.cnblogs.com/emanlee/p/9245942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!