summary() displays different outcomes.

Hi guys, i'm new to R and would like to seek your kind assistance.

As far as i know, if i type summary(object) will display the outcome rather than the properties. Did i missed anything important?

Thanks for the help.

********* Actual Outcome ****** 
> summary(resume)
  firstname             sex                race                call        
 Length:4870        Length:4870        Length:4870        Min.   :0.00000  
 Class :character   Class :character   Class :character   1st Qu.:0.00000  
 Mode  :character   Mode  :character   Mode  :character   Median :0.00000  
                                                          Mean   :0.08049  
                                                          3rd Qu.:0.00000  
                                                          Max.   :1.00000 

**** ANSWER ***
## > summary(resume)
## firstname      sex                race
## Tamika : 256 female:3746 black:2435
## Anne : 242    male :1124  white:2435
## Allison: 232
## Latonya: 230
## Emily : 227
## Latoya : 226
## (Other):3457


## call
## Min. :0.00000
## 1st Qu.:0.00000
## Median :0.00000
## Mean :0.08049
## 3rd Qu.:0.00000
## Max. :1.00000
##

Hi,

Welcome to the RStudio community!

The summary function is a generic function that generates a summary of your data based on the class of object and the type of data within. If you get different results than expected, that's likely because the object you're using has a different class.

To check the class of an object, use class()

Example:

#Data frame
myData = data.frame(x = 1:10, y = runif(10))
class(myData)
[1] "data.frame"
lapply(myData, class)
$`x`
[1] "integer"

$y
[1] "numeric"


summary(myData)
       x               y         
 Min.   : 1.00   Min.   :0.2182  
 1st Qu.: 3.25   1st Qu.:0.4429  
 Median : 5.50   Median :0.6601  
 Mean   : 5.50   Mean   :0.6518  
 3rd Qu.: 7.75   3rd Qu.:0.9208  
 Max.   :10.00   Max.   :0.9867  

#Matrix
myData = list(x = 1:10, y = runif(10))
class(myData)
[1] "list"
lapply(myData, class)
$`x`
[1] "integer"

$y
[1] "numeric"


summary(myData)
  Length Class  Mode   
x 10     -none- numeric
y 10     -none- numeric

Hope this helps,
PJ

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.