R “Data Types” represents the types of data R can handle and work with. In R, we have a few basic data types: characters, doubles, integers, logical, and complex numbers.
The data type of objects can be shown using the typeof() function R. This guide will show you how to use it to check data type in R.
Checking Data type in R
To check Data Type in R, use the typeof() function. The syntax of this function is:
typeof(obj)
For example, the following R script checks the data type of different variables.
string_value = 'Apple' #character
typeof(string_value)
integer_value <- 5L #integer
typeof(integer_value)
double_value <- 2.3 #double
typeof(double_value)
logical_value <- FALSE #double
typeof(logical_value)
complex_value <- 1 + 2i #complex number
typeof(complex_value)