Problem with accentuation - R

Asked

Viewed 3,531 times

1

I try to solve the problem of accents with this script:

Mapa@data$NAME_2 <- Mapa@data$NAME_2 %>% 
      as.character() %>% 
      stri_trans_general("Latin-ASCII") %>% 
      toupper()

But when I open the column NAME_2, the name of the municipalities is, for example: MACEIA³ instead of MACEIO or MACEIO. Mapa@data$NAME_2 is a column with the name of the municipalities of Brazil.

  • 2

    Which command are you using to read the data? You need to set the encoding to "utf-8".

2 answers

2

# Instalar o pacote abjutils, se ainda não tiver instalado:
# install.packages("abjutils")

library(abjutils)
x <- c("maceió", "acentuação")
rm_accent(x)
#> [1] "maceio"     "acentuacao"

Created on 2018-06-27 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).

Or, this topic has other answers: Remove accents

0

Test this:

#Ajustando codificação de caracters do dataset
df = apply(Mapa@data, 2, as.character) 
Encoding(df) = "UTF-8"
Mapa@data = as.data.frame(df)
  • I had already tried it, unfortunately it didn’t work. :(

  • Check the database, it may be that the error is not in reading by R, but in the data file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.