I'd like to convert a factor variable to a numeric one but as.numeric
doesn't have the effect I expect.
Below I get summary statistics for the numeric version of the variable based on the original variable. The means keep counting up by 1... perhaps (he speculates) the levels of the factor have both names and numbers, and I'm expecting the value of the new variable to come from the name when as.numeric
is designed to use the number?
> describe.by(as.numeric(df$sch), df$sch)
group:
var n mean sd median trimmed mad min max range skew kurtosis se
1 1 5389 1 0 1 1 0 1 1 0 NaN NaN 0
---------------------------------------------------------
group: 001
var n mean sd median trimmed mad min max range skew kurtosis se
1 1 19 2 0 2 2 0 2 2 0 NaN NaN 0
---------------------------------------------------------
group: 002
var n mean sd median trimmed mad min max range skew kurtosis se
1 1 54 3 0 3 3 0 3 3 0 NaN NaN 0
---------------------------------------------------------