Rookie
Rookie

Reputation: 5467

R get summary statistics value in R

I have a data-frame, say cluster. I know we can get the summary statistics as follows:

summary(cluster)

which give something like:

cluster     client       domain                  
Min.   :4   RRr_IL:40449   P621:409  
1st Qu.:4                              
Median :4                               
Mean   :4                              
3rd Qu.:4                              
Max.   :4                               

shift_end     shift_length_avg patients_seen_cnt
 Min.   : 0.00   Min.   :6.000    Min.   :  1.000  
 1st Qu.:13.00   1st Qu.:7.000    1st Qu.:  4.000  
Median :15.00   Median :8.000    Median :  6.000  
Mean   :13.93   Mean   :8.128    Mean   :  9.107  
3rd Qu.:17.00   3rd Qu.:9.000    3rd Qu.: 11.000  
Max.   :23.00   Max.   :9.000    Max.   :273.000  

How do i parse this summary. This seems to be a character array.

for example if i want to reach the median value for 'shift_length_avg ' from the summary, how would i do it?

Upvotes: 0

Views: 383

Answers (2)

Ven Yao
Ven Yao

Reputation: 3710

The result of summary is a table which is a character matrix.

summary(iris)
 #  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width          Species  
 # Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100   setosa    :50  
 # 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300   versicolor:50  
 # Median :5.800   Median :3.000   Median :4.350   Median :1.300   virginica :50  
 # Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199                  
 # 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800                  
 # Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500                  

str(summary(iris))
 # 'table' chr [1:6, 1:5] "Min.   :4.300  " "1st Qu.:5.100  " ...
 # - attr(*, "dimnames")=List of 2
 #  ..$ : chr [1:6] "" "" "" "" ...
 #  ..$ : chr [1:5] " Sepal.Length" " Sepal.Width" " Petal.Length" " Petal.Width" ...

summary(iris)[, 3]

# "Min.   :1.000  " "1st Qu.:1.600  " "Median :4.350  " "Mean   :3.758  " 
# "3rd Qu.:5.100  " "Max.   :6.900  " 

colnames(summary(iris))
# [1] " Sepal.Length" " Sepal.Width"  " Petal.Length" " Petal.Width"  "      Species"

summary(iris)[, " Petal.Length"]

# "Min.   :1.000  " "1st Qu.:1.600  " "Median :4.350  " "Mean   :3.758  " 
# "3rd Qu.:5.100  " "Max.   :6.900  " 

Upvotes: 1

CuriousBeing
CuriousBeing

Reputation: 1632

Try this:

Med<-median(cluster$shift_length_avg, na.rm = FALSE)

Upvotes: 0

Related Questions