IN r, how to combine the summary together

后端 未结 2 1313
鱼传尺愫
鱼传尺愫 2021-02-09 04:34

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          


        
相关标签:
2条回答
  • 2021-02-09 04:55

    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
    
    0 讨论(0)
  • 2021-02-09 04:57

    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)
    
    0 讨论(0)
提交回复
热议问题