[R] summary and logical

Martin Maechler maechler at stat.math.ethz.ch
Thu Oct 3 14:30:09 CEST 2002


>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk>
>>>>>     on 03 Oct 2002 11:20:21 +0200 writes:

    PD> Göran Broström <gb at stat.umu.se> writes:
    >> In R-1.6.0 (Linux) I notice that 'summary' on a
    >> data.frame doesn't treat logicals nicely. I only get
    >> 
    >> event Length:148939 Mode :logical
    >> 
    >> Is this a bug? (I expected frequencies for TRUE and
    >> FALSE, of course.)

    PD> Not a bug, but a fairly obviously missing
    PD> feature... Logicals used to be automatically converted
    PD> to factors so it wasn't noticed earlier.

    PD> Looks like a one-line change to summary.default, so we
    PD> might just be convinced to put it in for 1.6.1, even if
    PD> it's not strictly a bug.

"yes" I said instinctivly -- but then realized that S-plus 6.1
doesn't summary()ze differently either.  

So we might be more careful...

Anyway, I'd want that after the change,

  lvar <- (1:20 %% 3 == 1)
  summary(lvar) ## and
  summary(as.factor(lvar))

*be* distinguishable.
If we do the change, (I'm "make checking" it), we should make it
distinguishibly, maybe even adding the word (line) "logical", e.g., like

> summary(lvar)
   Mode   FALSE    TRUE 
logical      13       7 

and {used in summary.data.frame()} :
 
> sd <- summary(data.frame(x=1:10, y=round(rnorm(10),2), F=gl(2,5),L=(1:10)>7))
> sd
       x               y          F         L          
 Min.   : 1.00   Min.   :-1.120   1:5   Mode :logical  
 1st Qu.: 3.25   1st Qu.:-0.790   2:5   FALSE:7        
 Median : 5.50   Median :-0.695         TRUE :3        
 Mean   : 5.50   Mean   :-0.223                        
 3rd Qu.: 7.75   3rd Qu.: 0.390                        
 Max.   :10.00   Max.   : 1.530                        
> str(sd)
 chr [1:6, 1:4] "Min.   : 1.00  " "1st Qu.: 3.25  " "Median : 5.50  " ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "" "" "" "" ...
  ..$ : chr [1:4] "      x" "      y" "F" "    L"
 - attr(*, "class")= chr "table"
> 

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list