1
I have a data_frame with two columns (UF and Municipality). I want to create a new column named region through the column UF. I did what described below, but it was a mistake. I’m a beginner in R and would like to understand my mistake. Can help me?
if populacao$UF == ("AM", "AP", "AC", "RR", "PA", "RO", "TO") {
populacao$regiao <- "Norte"
} else if populacao$UF == c("MA", "PI", "CE", "RN", "PE", "PB", "SE", "AL", "BA") {
populacao$regiao <- "Nordeste"
} else if populacao$UF == c("MT", "MS", "GO") {
populacao$regiao <- "Centro-Oeste"
} else ifpopulacao$UF == c("SP", "RJ", "ES", "MG"){
populacao$regiao <- "Sudeste"
} else if populacao$UF == c("PR", "SC", "RS"){
populacao$regiao <- "Sul"
} else {
populacao$regiao <- "ERRO"
}
Please put one on
dput()
of your data.– Alexandre Sanches
As I said I am beginner. I thank you for your collaboration. What would be dput()?
– Patricia Pelissari
The function
dput()
returns a data.frame with your data. Read How to ask a good question?– Alexandre Sanches
See also here, although the question is not exactly the same.
– Rui Barradas