-1

Has summary() always displayed character vectors in this manner? I don't remember this being the case.

Using sample dataset

install.packages("mlbench")
library(mlbench)

Examine contents and see all numeric vectors except for one column "chas" as factors

#shortened for easier readability
BostonHousing <- BostonHousing[,c(1:4)]

str(BostonHousing)
#'data.frame':  506 obs. of  4 variables:
 #$ crim : num  0.00632 0.02731 0.02729 0.03237 0.06905 ...
 #$ zn   : num  18 0 0 0 0 0 12.5 12.5 12.5 12.5 ...
 #$ indus: num  2.31 7.07 7.07 2.18 2.18 2.18 7.87 7.87 7.87 7.87 ...
 #$ chas : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...

summary(BostonHousing)
#crim                zn             indus       chas   
 #Min.   : 0.00632   Min.   :  0.00   Min.   : 0.46   0:471  
 #1st Qu.: 0.08204   1st Qu.:  0.00   1st Qu.: 5.19   1: 35  
 #Median : 0.25651   Median :  0.00   Median : 9.69          
 #Mean   : 3.61352   Mean   : 11.36   Mean   :11.14          
 #3rd Qu.: 3.67708   3rd Qu.: 12.50   3rd Qu.:18.10          
 #Max.   :88.97620   Max.   :100.00   Max.   :27.74   

Change 'chas' to a character vector.

BostonHousing$chas <- as.character(BostonHousing$chas)

Now when I go to run summary the 'chas' column shows NULL. I thought I remember seeing the column name with (character) and dimensions displayed underneath.

head(summary(BostonHousing))

  crim                zn             indus         chas  
 Min.   : 0.00632   Min.   :  0.00   Min.   : 0.46   NULL:0  
 1st Qu.: 0.08204   1st Qu.:  0.00   1st Qu.: 5.19   NULL:0  
 Median : 0.25651   Median :  0.00   Median : 9.69   NULL:0  
 Mean   : 3.61352   Mean   : 11.36   Mean   :11.14   NULL:0  
 3rd Qu.: 3.67708   3rd Qu.: 12.50   3rd Qu.:18.10   NULL:0  
 Max.   :88.97620   Max.   :100.00   Max.   :27.74   NULL:0 
panstotts
  • 623
  • 1
  • 5
  • 13
  • I can't replicate your result. It works fine for me and returns `Length:506 Class: character Mode: character` for the `chas` column. Also, just `summary(BostonHousing)` will do it, or `summary(head(BostonHousing))` - don't put the `head()` as the outermost function. – thelatemail Oct 12 '16 at 22:07

1 Answers1

1

Appears I installed a buggy package or had something overridden. I restarted R Studio/computer and now working fine showing: Length:506, Length:506, Mode:character:

summary(BostonHousing)

      crim                zn             indus           chas          
 Min.   : 0.00632   Min.   :  0.00   Min.   : 0.46   Length:506        
 1st Qu.: 0.08204   1st Qu.:  0.00   1st Qu.: 5.19   Length:506 
 Median : 0.25651   Median :  0.00   Median : 9.69   Mode  :character  
 Mean   : 3.61352   Mean   : 11.36   Mean   :11.14                     
 3rd Qu.: 3.67708   3rd Qu.: 12.50   3rd Qu.:18.10                     
 Max.   :88.97620   Max.   :100.00   Max.   :27.74                     
panstotts
  • 623
  • 1
  • 5
  • 13