What is the iconv() function in R?

Overview

The iconv() function in R is used to convert given character vectors between encodings.

Syntax


iconv(x, from = "", to = "")

Parameter values

The iconv() function takes the following parameter values:

  • x: This represents the character vector of the object to be converted.

  • from: This is a character string that describes the current encoding.

  • to: This is a character string that describes the desired encoding.

Return value

The iconv() function returns a character vector that has the same length as x.

Code

x <- "fa\xE7ile"
iconv(x, "ISO_8859-2", "UTF-8")

Explanation

  • Line 1: We create a character vector x of the ISO_8859-2 encoding.

  • Line 2: We use the iconv() function to convert the input character object from ISO_8859-2 encoding to UTF-8 encoding.

Free Resources