I have a dataframe named "Num_casos_Sar" with a structure like that:
Cod_municip Ano Not_Sarampo
1 310110 1989 3
2 310160 1988 0
3 310350 1985 6
4 310620 1988 2
5 310640 1988 0
6 310670 2017 3
I would like that each value in my column "Ano" become a column. I tryed to execute a code using tidyr, but I did not have sucess:
Num_casos_Sar <- Num_casos_Sar %>%
separate(Ano, into = paste("Ano", seq_along(Ano), sep = ""), sep = "")
tidyr::pivot_wider(Num_casos_Sar, id_cols = "Cod_municip", names_from = "Ano", values_from = "Not_Sarampo")
, and see MrFlick's link as well as stackoverflow.com/q/11608167/3358272 for more discussion/examples.