So, I've seen some similar questions, but the solutions there don't appear to work, so I assume I've either done something wrong or I don't have exactly the same problem.
I'm using dbReadTable
to download data from an SQL server for analysis. The data has a variable which can have currency symbols in a character string, e.g. £. The variable can have one of 9 possible values with the £ symbol appearing 0, 1 or 2 times in various places in the string (I'm not able to share the options here due to data sensitivity) but one example could be...
"[text]£[text]£[text]"
On the SQL db, these display correctly and have class varchar
. Once downloaded as a data.frame
, the variable has class character
. However, the £ symbols now either displaying as "< U+00A3>" (when Viewing the data.frame
) or � (when checking the value for an observation). I've tried using gsub
and stri_replace_all_fixed
to replace the "< U+00A3>" values in the variable, but it doesn't seem to find anything to replace. Below is some code showing what I've done.
con1 <- dbConnect(odbc(), dsn = dsn1, Database = dbase1)
cube1 <- dbReadTable(con1, table1)
cube1$variable <- stri_replace_all_fixed(cube1$variable, "<U+00A3>", "")
cube1$variable <- gsub("^.+<U\\+\\w+>.+$", "", cube1$variable)
Neither of those last 2 lines did anything and I'm still stuck with the "< U+00A3>" or � values (depending on how you look at the values for the variable). As a test, I did check to see if £ symbols display when entered in the Console, and they do...
> x = c("£2")
> x
[1] "£2"
I'm looking to either get the £ symbol to display correctly or to remove it from the variable (or solutions for both options).