Variables are used to store data in any programming language. In R language, The type of the data is checked at run time. The different data types in R include: Character, Numeric , Integer, Factor and Logical.
There are a few instances where we need to convert one data type into another to further use the information in order to perform operations. This is known as data type-casting.
In this recipe, We will demonstrate how to type-cast integer values into character (also known as string in other languages).
We use the as.integer() function to define any integer value
a = as.integer(2)
To check the data type of a variable, we use class() function
We use as.character() function to convert any data type to character/string data type
b = as.character(a) b
'2'To check the data type of a variable, we use class() function