Mean function in R (Dealing with factors)
r
Solution
It looks like `x` is a factor. There is a gotcha when converting factors to numbers. You need to use:
mean(as.numeric(as.character(x)), na.rm=TRUE)
If you don't convert to character first, you will get the underlying factor codes.
Problem
So I have this vector: ``` x [1] 76 89 78 50 84 56 29 53 32 68 112 Levels: 0 1 10 100 101 102 103 104 105 106 107 108 109 11 110 12 13 ... eta ``` why this happens? ``` [1] NA Warning message: In mean.default(x) : l'argomento non è numerico o logico: restituisco NA ```