Convert encoding of character and factor variables in a dataframe

convertdf_enc(x, from = "", to = "UTF-8", sub = NA, colnames = FALSE)

Arguments

x

An object with the data.frame class (such as data.frame or sf)

from

A character string describing the current encoding.

to

A character string describing the target encoding.

sub

character string. If not NA it is used to replace any non-convertible bytes in the input. (This would normally be a single character, but can be more.) If "byte", the indication is "<xx>" with the hex code of the byte. If "Unicode" and converting from UTF-8, the Unicode point in the form "<U+xxxx>", or if c99, a C99-style escape "\uxxxx".

colnames

Should column names be converted as well?

Value

The original object, with character variables (and levels of (character) factor variables) converted to the specified encoding.

Details

Encoding strings: all R platforms support "" (for the encoding of the current locale), "latin1" and "UTF-8". See iconv for more information.

See also

Other Data_handling_utilities: csv_to_sqlite(), df_factors_to_char()