Starting from this df:
df <- structure(list(Cod = "007", Mun = “Siguenza”, Mesas = "00002",
Censo = "00000731", Escrut = "00000100", `%Censo` = "100",
Votantes = "00000480", `%Votantes` = "00060", Abst = "00000220",
`%Abst` = "00035", Blanc = "00000100", `%Blanc` = "00010",
Nulos = "00000100", `%Nulos` = "00010", Elegir = "007", P1 = "0004",
S1 = "PSE", V1 = "00000300", `%V1` = "00040", C1 = "005",
P2 = "2187", S2 = "CBiz", V2 = "00000100", `%V2` = "00030",
C2 = "001", P3 = "0002", S3 = "POP", V3 = "00000100", `%V3` = "00030",
C3 = "001"), row.names = c(NA, -1L), class = c("tbl_df", "tbl", "data.frame"))
I want to change character to number (except Mun, S1, S2 and S3), remove leading zeros and obtain two dataframes with this structure:
Cod | 7 | |
---|---|---|
Municipio | Siguenza | |
Mesas | 2 | |
Censo | 731 | |
Escrutado | 100 | |
%Censo | 100 | |
Votantes | 480 | |
%Votantes | 60 | |
Abst | 220 | |
%Abst | 35 | |
Blanco | 100 | |
%Blanco | 10 | |
Nulos | 100 | |
%Nulos | 10 | |
Elegir | 7 |
and
Id | Part | Vot | %Vot | Elec |
---|---|---|---|---|
4 | PSE | 300 | 40 | 5 |
2187 | Cbiz | 100 | 30 | 1 |
2 | POP | 100 | 30 | 1 |
where id is equal to P1, P2 and P3; part is equal to S1,S2 and S3 and so on. No idea where to start.
Regards.