Power BI Power Query R

How to convert accented characters to unaccented in R or Power BI

Sometimes it’s necessary to convert accented characters to non accented in R or Power BI for text analysis purposes. Accented characters might be a problem in texts with spelling mistakes and spoil the analysis.

Convert accented characters in R

Luckily in R is a base function iconv that makes this task easy. You only have to adjust the target encoding.

iconv("schön, natürlich", to = 'ASCII//TRANSLIT')

iconv("tā ir dzīve", to = 'Latin1')

 

If you want to know how useful RStudio tips and tricks, take a look at this post.

Convert accented characters in Power BI (Power Query)

First of all, R should be installed on your workstation.
Open Power Query editor, go to the Transform tab and choose Run R script.

Use the iconv function to convert the dataset column with accented characters. It worked only if the current encoding parameter (from) was defined.

# 'dataset' holds the input data for this script

dataset$text <- iconv(dataset$text, from = 'UTF-8', to = 'ASCII//TRANSLIT')

output <- dataset

Here is the result.

Here is another example of how to run R script in Power Query.

2 comments on “How to convert accented characters to unaccented in R or Power BI

  1. Just amazing! thanks

  2. That’s incredible. It’s crazy to realize we can use M, Python and R in the same environment and we get to choose which is better for a especific situation.

Leave a Reply

Your email address will not be published. Required fields are marked *