How to convert factor variable to a numeric vector in R?

r
plot

#1

I am currently trying to plot a location using longitude and latitude but in my data longitude and latitude given in the factored form.I want to know how I can convert the factor variable to a numeric vector by which I can plot the location.

str(LatLonCounts)
'data.frame':   1638 obs. of  3 variables:
 $ Var1: Factor w/ 42 levels "-87.93","-87.92",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ Var2: Factor w/ 39 levels "41.64","41.65",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Freq: int  0 0 0 0 0 0 0 0 0 0 ...

Here Var1 and Var2 are longitude and latitude.


#2

Hi Harry,

before to undo the factor, check how you came there, did you get from cvs and did not use stringsAsFactor=FALSE or a rbind?? With GIS it is seldom that the dataset is suppose to be factor.
Anyway if you want to do the transformation:
intermediate <-unclass(LatLonCounts$Var1)
LatLonCounts$Var1<-as.numeric(attributes(intermediate)[Intermediate])
and you got it. But as mentioned check how you load those data
Alain