[R] Weird problem with median on a factor

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Oct 31 10:28:23 CET 2003


Christoph Bier <christoph.bier at web.de> writes:

> 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?

Offhand, I'd guess that the "median" is inbetween two factor levels in
one case and not in the other. However, both cases should give an
error, especially for unordered factors, but it is not well-defined
for ordered factors either. If you want to interpret your factor as a
numeric scale, use as.numeric first.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list