Introduction
R is a popular computer language for statistical computation and data analysis. It is a popular choice among professionals due to its numerous advantages. R enables users to analyse and visualise data effectively. It is because of its great support for statistical processes and image production. R is a free and open-source programming language. Anyone interested in data science should look at R. It is adaptable, can communicate with other tools, and is widely used in academics and industry.

In this article, we will have an Introduction to R Data Types.
Data Types in R
So, What is data type? Well, just like there are different genres in movies. Data too are categorised in different ways too. In the R Programming language, data objects are assigned specific data types to represent different kinds of information. In this comprehensive guide, we will delve into five important data types in R, progressing from the simplest to the most complex; logical, integer, double, complex numbers, and strings. By understanding these data types, you will gain a solid foundation for working with diverse data in R.
Logical
Logical data type or Boolean data type, In R, there isn’t exactly a difference between them. The logical data type is the most basic in R, considering it has only two values: TRUE or FALSE. Logical values are commonly encountered when performing comparisons or running tests in R.
Given below are various examples of Logical data types.
Example:
# Logical example
result <- 5 >= 3
print(result)
# Output: TRUE
values <- c(1, 2, 3, 4, 5) >= c(5, 4, 3, 2, 1)
print(values)
# Output: FALSE FALSE TRUE TRUE TRUE
lazy_logical <- T
print(lazy_logical)
# Output: TRUE
lazy_logical <- F
print(lazy_logical)
# Output: FALSE
Integer
Integers are denoted by a number followed by the letter "L." Integers do not have any decimals. The integer data type represents whole numbers in R. Unlike other programming languages, R explicitly distinguishes integers from floating-point numbers (doubles).
Given below are various examples of Integer data types.
Example:
# Integer example
not_integer <- typeof(1)
print(not_integer)
# Output: "double"
integer_value <- typeof(1L)
print(integer_value)
# Output: "integer"
result <- 1L + 1.5
print(result)
# Output: 2.5
Double
The double data type is short for a double-precision number. It is the primary numeric data type in R. Doubles are used to represent real numbers with decimal places and can handle a wide range of numeric values.
Given below are various examples of Double data types.
Example:
# Double example
result <- typeof(1)
print(result)
# Output: "double"
result <- typeof(3.4)
print(result)
# Output: "double"
result <- typeof(-3e15)
print(result)
# Output: "double"
result <- typeof(1/3)
print(result)
# Output: "double"
Complex Number
The R language has separate data types for complex numbers, unlike other languages. Because R is a language that is focused on statistics and data, a complex number is required. R supports complex numbers, which consist of a real part and an imaginary part. Complex numbers are represented as “<real> + <imaginary>i” in R. Although less frequently used, they are essential for certain mathematical computations.
Given below are various examples of Complex Number data types.
Example:
# Complex number example
result <- sqrt(-1)
print(result)
# Output: NaN (Not a Number)
result <- sqrt(-1 + 0i)
print(result)
# Output: 0 + 1i
String
The string data type in R is also interchangeably used with the character data type. It is used to handle textual data in R. Strings are enclosed in either single quotes (') or double quotes ("). They can contain any character or sequence of characters.
Given below are various examples of String data types.
Example:
# String example
letters <- "abcdefg"
print(letters)
# Output: "abcdefg"
numbers <- '12345678'
print(numbers)
# Output: '12345678'
sentence <- "string of words"
print(sentence)
# Output: "string of words"