I am ploting a dataframe into a shapefile map, but I need to repair a bunch of these codes.
Well. The map have 3 areas, identify by codes. 2 areas works good with the code, but all of the codes that start with 3 don´t work. These numbers need to start with 03.
So if I have 3002 in the dataframe, I need to repair to 03002. So
It´s possible to make it from R?
This is a bit of my code: The column to repair with the 0 at the first 3´s its called "code2"
dfcsv1 <- read.csv("https://dadesobertes.gva.es/datastore/dump/e23bf332-be3e-4a3a-a07b-300db3d9a7be?bom=True", encoding = "UTF-8", header = TRUE, sep = ",")
colnames(dfcsv1) <- c("code", "code2", "Municipio", "PCR", "TasaPCR", "PCR14", "TasaPCR14", "Muertos", "TasaMuertos")
dfcsv1$TasaMuertos = as.numeric(gsub(",","\\.",dfcsv1$TasaMuertos))
dfcsv1$TasaPCR = as.numeric(gsub(",","\\.",dfcsv1$TasaPCR))
dfcsv1$TasaPCR14 = as.numeric(gsub(",","\\.",dfcsv1$TasaPCR14))
dfcsv1 <- dfcsv1 %>%
mutate(
municipio = stringr::str_c(code2)
)
mapa_df <- mapa_df %>%
left_join(
y = dfcsv1 %>% select(municipio, TasaPCR14),
by = "municipio"
)
thank you all in advance!