1 Answers

fac <- factor(c(2.3, 1.5, 3, 4.9))

as.numeric(fac)

I obtain the output as – 2,1,3,4 which is clearly not what was expected. How should I rectify

this problem?

In the above code, you are converting factor to number which is problematic. R simply floors the

values without any warning. In order to convert factors to numbers properly, we use the integer

vector to perform indexing on the factor levels as follows –

levels(fac)[fac]

Have you checked R factor analysis