简体   繁体   中英

How to fix special characters in R? REPLACEMENT CHARACTER

I have a problem with some data I´m working. I extrac data from SQL SERVER and with RI work them, but for some fields of names, some names have instead of a letter the REPLACEMENT CHARACTER (Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)), is the one enter image description here I don´t want to use the replace function, to change the entire name. Some ideas?

example the name MAGAÑA: MAGA A

I use the following code to the connection and query:

library(odbc)
library(tidyverse)
library(dgof)
library(pROC)
library(ggplot2)
library(dbplyr)
library(dplyr)
library(lubridate)
library(janitor)
library(DBI)
library(readxl)
library(data.table)

## Connection

conex1 <- dbConnect(odbc(),
                Driver = "SQL Server",
                Server = "xxx.xxx.xxx.xx",
                Database = "xxxxxxxx",
                UID = "xxxxxxx",
                PWD = "xxxxxxxxx",
                Port = 1433)

# Query

Fecha_nac<- dbSendQuery(conex1, "SELECT id_orden, 
fecha_nacimiento
  FROM zzgm_clientes_xxxxxxx") %>% 
dbFetch()

I think, iconv can help to you in this situation.

dataframe_with_right_symbols <- raw_dataframe %>%
      mutate_if(is.character, function(col) iconv(col, to="UTF-8"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM