Q:

Converting character attribute to numeric attribute

I am following the very simple code found in this question:
Converting shapefile to raster: Character attributes
to create a new numeric variable based on a factor. My problem is that the new numeric attribute has a complete different series of numbers than the factor column.
For example, instead of reading: 18001, 18002, 18003, it converts these numbers into 786, 894, 895: I have tried as.numeric and as.integer, and none of these work.
For further details, the shapefile column is described as:
commune_5m@data$NUMERO: Factor w/ 1842 levels "18001", "18002", ...: 786 894 895

A:

Sorry, The solution was very simple, I needed to convert to character before converting to numeric:
commune_5m@data$NUMERO2 = as.numeric(as.character(commune_5m@data$NUMERO)) 
### Create numeric attribute from factor

