First would be good if you exposed your data or a part of them to make the problem reproducible. But, here taking a generic case.
library(dplyr)
tibble(uf=c("AM", "RJ", "SC"),
regiao=c("norte", "sudeste", "sul"),
ano=c(1989, 1987, 1986),
pop=runif(3)) %>%
print() %>%
{.} -> dt
# uf regiao ano pop
# <chr> <chr> <dbl> <dbl>
#1 AM norte 1989 0.05092618
#2 RJ sudeste 1987 0.54035176
#3 SC sul 1986 0.54615493
To change the type of variables, just apply the mutate
function of the dplyr
package. In the date part you should set a day and a month to use the date type, in the example below I used the first of January, which will be applied to all the lines.
dt %>%
mutate(regiao=as.factor(regiao)) %>%
mutate(ano=as.Date(ISOdate(ano, 1, 1)))
# uf regiao ano pop
# <chr> <fctr> <date> <dbl>
#1 AM norte 1989-01-01 0.05092618
#2 RJ sudeste 1987-01-01 0.54035176
#3 SC sul 1986-01-01 0.54615493
What you could do differently here would be to use a single mutate
to change both columns, such as:
dt %>%
mutate(regiao=as.factor(regiao),
ano=as.Date(ISOdate(ano, 1, 1)))