[R] inconsistent behavior of mean, median, var

Richard M. Heiberger rmh at temple.edu
Mon Jan 22 03:52:30 CET 2007


> mean(c("-1","0", "1"))
[1] NA
Warning message:
argument is not numeric or logical: returning NA in: mean.default(c("-1", "0", "1")) 
> median(c("-1","0", "1"))
Error in median.default(c("-1", "0", "1")) : 
        need numeric data
> var(c("-1","0", "1"))
[1] 1
> 


Is the above intentional behavior?  mean and median of character data
give a warning and error.  var gives the result of coercing the argument
to numeric.



More information about the R-help mailing list