[R] Weird problem with median on a factor

Christoph Bier christoph.bier at web.de
Sun Nov 2 11:55:41 CET 2003


Dave Cacela schrieb:
> Christoph,
> 
> I concur with the other respondents who questioned why someone would wish to
> calculate the median of a factor. However, with regard to your actual
> question, I suspect that median() is giving different answers because the
> two vectors are not both factors, i.e., that one of them is a character. Did
> you test that? 

Yes, I did and find the same like Tony Plate:

 > is.factor(fbhint.spss1$V15.SPS) # = column 264
[1] TRUE
 > mode(fbhint.spss1$V15.SPS)
[1] "numeric"
 > is.factor(fbhint.spss1$V15.SP1) # = column 566
[1] TRUE
 > mode(fbhint.spss1$V15.SP1)
[1] "numeric"

> Using S, I have seen quirks in this regard that relate to import procedure
> and the value of the first element in the vector. In your case, the first
> elements differ in that one is NA while the other is "teils/teils".  

It also occurs if the first element is the same. For example "wichtig" in 
columns 263 and 565.

Regards,

Christoph




More information about the R-help mailing list