I want to change the official geographic codes (insee codes) of French communes from 2012 to 2019, within a data frame in R.
To do so, I am using the function changement_COG_varNum from antuki/COGugaison package. It worked pretty well for many other data frames. But it doesn't work for one of them:
test <- changement_COG_varNum(table_entree=communes_cz_19,annees=c(2012:2019),codgeo_entree="COG19",agregation=F,libgeo=F,donnees_insee=T)
Error in Ops.data.frame(provisoire[, c(var_num, "ratio")], provisoire[, :
‘*’ only defined for equally-sized data frames
The data frame "communes_cz_19" is a sf containing the geometry of communes in France on 2012. I thought it might be the problem with the geometry variable, so I extracted the COG codes in another data frame (result) and tried again. Here is the code to simulate the first 10 rows of my data:
result <- tribble(~COG12,c("14078","57324","14144","76496","80481","02129","78158","51336","50160","64129"))
result <- unnest(result,COG12)
result$COG19 <- result$COG12
result <- as.data.frame(result)
devtools::install_github("antuki/COGugaison")
library(COGugaison)
result <- changement_COG_varNum(table_entree=result,annees=c(2012:2019),codgeo_entree="COG19",agregation=F,libgeo=F,donnees_insee=T)
Now it says:
Error in (provisoire[, c(var_num, "ratio")] * provisoire[, "ratio"])[, :
incorrect number of dimensions
I cannot recognize the difference between this example and the other cases for which I could do the same without any problem! What am I doing wrong? What should I do?