zoukankan      html  css  js  c++  java
  • Restructure output of R summary function


     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

  • 相关阅读:
    CodeForces
    CodeForces
    sort自定义cmp函数
    The 2015 China Collegiate Programming Contest Sudoku
    G
    docker
    在容器内获取Pod信息(Downward API)
    k8s Pod定义详解
    Pod和容器的生命周期管理
    GoAccess日志分析工具
  • 原文地址:https://www.cnblogs.com/emanlee/p/9245942.html
Copyright © 2011-2022 走看看