Search code examples
rsummary

Different output format summary(X$Y) vs summary(X)


I am a beginner in R, but I am aware I should look for answers before asking a question here. I did, looked into help files, but to no avail. The problem is as follows: when I ask for a summary of subset X, the output of the two columns is as below. I wanted to have only the output for the answer, which I am able to to, but it is presented differently (see the output at the bottom). I want to have the results presented as a table, not as a list.

summary(X, max = 12)

results in:

student            answer    


 Min.   :    335   0 - Not at all likely                                                                 :  35  
 1st Qu.: 855480   1                                                                                     :  18  
 Median :1831962   10 - Extremely likely                                                                 :9336  
 Mean   :1519041   2                                                                                     :  23  
 3rd Qu.:2183663   3                                                                                     :  19  
 Max.   :2607132   4                                                                                     :  15  
                   5 - Neutral                                                                           : 939  
                   6                                                                                     : 235  
                   7                                                                                     : 921  
                   8                                                                                     :1844  
                   9                                                                                     :1194  
                   option_i4x-DelftX-ET3034TUx-problem-b3d30df864ca41ffa0170e790f01a783_2_1_dummy_default:  71

Because I am only interested in the summary stats for answer, I used

summary(X$answer, max = 12)

And then I get the list below as answer.

                                                             0 - Not at all likely 
                                                                                35 
                                                                                 1 
                                                                                18 
                                                             10 - Extremely likely 
                                                                              9336 
                                                                                 2 
                                                                                23 
                                                                                 3 
                                                                                19 
                                                                                 4 
                                                                                15 
                                                                       5 - Neutral 
                                                                               939 
                                                                                 6 
                                                                               235 
                                                                                 7 
                                                                               921 
                                                                                 8 
                                                                              1844 
                                                                                 9 
                                                                              1194 
option_i4x-DelftX-ET3034TUx-problem-b3d30df864ca41ffa0170e790f01a783_2_1_dummy_default 
                                                                                71 

Solution

  • You should try

    summary(X["answer"], max = 12)
    

    since X["answer"] is not a vector like X$answer but a one-column data frame.