R - How to convert all columns of a data.table encoding?

Asked

Viewed 133 times

0

Hello !

I’ve been through the documentation data.table() , but I still can’t fully understand.

How would this function, for a dt ?

for(i in 1:ncol(df1))
{

    df1[,i] <- df1[,i] %>% iconv(from = 'UTF-8', to = 'latin1')

}

In a data.frame it converts all columns from UTF-8 to latin1.

Some simpler way ?

Thank you!

  • 1

    It may be easier to read the data with the function fread() which allows to define the encoding: fread('file.txt, encoding = "latin1")?

  • Yes ! but it turns out that I imported a very large base and only now I tried to encoding. To import again will take. Then I’d like another way out.

  • I found that answer: https://stackoverflow.com/questions/24492969/apply-encoding-to-entire-data-table

  • 1

    Maybe dt[, lapply(.SD, iconv, from = 'UTF-8', to = 'latin1')].

No answers

Browser other questions tagged

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