If you use as.numeric() directly on a factor, the result would be a vector of the internal level representations of the factor and not the original values.
So, to convert a factor to a numeric with its original values intact, you need to either:
Index the levels by the factor itself, and then to convert to numeric
Use a nested function as.numeric(as.character(factor))
For example:
f <- factor(sample(runif(5), 20, replace = TRUE))
num <- as.numeric(as.character(f))
num
Output:
[1] 0.4814881 0.4814881 0.8672543 0.1002661 0.8672543 0.1002661 0.3246189 0.4814881
[9] 0.7017931 0.1002661 0.3246189 0.8672543 0.3246189 0.3246189 0.8672543 0.8672543
[17] 0.8672543 0.3246189 0.4814881 0.3246189