Is there any possibility to declare the data type of the attribute columns when importing, for example, a ESRI Shapefile with the readOGR
command?
For example, I would like to keep the leading zeros in my key column (id_code
):
example<- readOGR(example.shp", example")
str(example@data)
#'data.frame': 7149 obs. of 22 variables:
# $ id_code: num 101 102 103 104 105 106 107 108 109 110 ...
The result should something be like this:
str(example@data)
#'data.frame': 7149 obs. of 22 variables:
# $ id_code: char "0101" "0102" "0103" "0104" "0105" "0106"...
I am looking for something similar as colClasses
in the read.csv()
function