[R] Weird problem with median on a factor

Simon Fear Simon.Fear at synequanon.com
Fri Oct 31 10:18:06 CET 2003


What do you expect the median of a factor to be? Are
you sure you don't want the *mode* (most common
value)?
If you want the median numeric code of ordered
factors, maybe use `as.numeric` first. Consider what you
think should happen if this median is not an integer.

HTH

> -----Original Message-----
> From: Christoph Bier [mailto:christoph.bier at web.de]
> Sent: 30 October 2003 21:35
> To: r-help at stat.math.ethz.ch
> Subject: [R] Weird problem with median on a factor
> 
> 
> Security Warning: 
> If you are not sure an attachment is safe to open please contact  
> Andy on x234. There are 0 attachments with this message. 
> ________________________________________________________________ 
>  
> Hi all,
> 
> I hope this isn't a naive newbie question again. Here you can 
> see column 264 of
> a data frame containing data of the same interview in May and 
> September. Column
> 264 contains the answers of 49 persons to a question in May.
> 
> > fbhint.spss1[,264]
>   [1] teils/teils  sehr wichtig <NA>         <NA>         sehr wichtig
>   [6] sehr wichtig sehr wichtig sehr wichtig <NA>         <NA>
> [11] <NA>         <NA>         wichtig      <NA>         <NA>
> [16] sehr wichtig <NA>         <NA>         <NA>         <NA>
> [21] <NA>         <NA>         <NA>         wichtig      <NA>
> [26] <NA>         <NA>         <NA>         <NA>         <NA>
> [31] <NA>         <NA>         <NA>         <NA>         teils/teils
> [36] sehr wichtig <NA>         <NA>         <NA>         <NA>
> [41] wichtig      <NA>         sehr wichtig <NA>         <NA>
> [46] sehr wichtig wichtig      <NA>         <NA>
> Levels: sehr wichtig wichtig teils/teils unwichtig ganz unwichtig
> 
> Column 566 contains the answers from the same persons to the 
> same question in
> September.
> 
> > fbhint.spss1[,566]
>   [1] <NA>         <NA>         <NA>         wichtig      wichtig
>   [6] sehr wichtig sehr wichtig wichtig      wichtig      <NA>
> [11] <NA>         <NA>         sehr wichtig sehr wichtig sehr wichtig
> [16] sehr wichtig <NA>         unwichtig    wichtig      wichtig
> [21] <NA>         <NA>         teils/teils  teils/teils  <NA>
> [26] unwichtig    <NA>         <NA>         <NA>         <NA>
> [31] wichtig      sehr wichtig sehr wichtig <NA>         unwichtig
> [36] sehr wichtig <NA>         <NA>         teils/teils  wichtig
> [41] wichtig      wichtig      <NA>         <NA>         wichtig
> [46] <NA>         sehr wichtig teils/teils  <NA>
> Levels: sehr wichtig wichtig teils/teils unwichtig ganz unwichtig
> 
> The following works:
> 
> > median(fbhint.spss1[,264], na.rm=T)
> [1] sehr wichtig
> Levels: sehr wichtig wichtig teils/teils unwichtig ganz unwichtig
> 
> ... but here it doesn't:
> 
> > median(fbhint.spss1[,566], na.rm=T)
> Error in Summary.factor(..., na.rm = na.rm) :
>          "sum" not meaningful for factors
> 
> I don't have any ideas why! Can somebody give me a hint?
> 
> TIA
> 
> Best regards,
> 
> Christoph
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>  
 
Simon Fear 
Senior Statistician 
Syne qua non Ltd 
Tel: +44 (0) 1379 644449 
Fax: +44 (0) 1379 644445 
email: Simon.Fear at synequanon.com 
web: http://www.synequanon.com 
  
Number of attachments included with this message: 0 
  
This message (and any associated files) is confidential and\...{{dropped}}




More information about the R-help mailing list