Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconData Sciencebreadcumb forward arrow iconTop 5 R Data Types | R Data Types You Should Know About

Top 5 R Data Types | R Data Types You Should Know About

Last updated:
27th Sep, 2020
Read Time
7 Mins
share image icon
In this article
Chevron in toc
View All
Top 5 R Data Types | R Data Types You Should Know About

Certain variables are needed to store the data that you are using within the program to create any application or render any programming in any programming language. One may also note (usually in typical or most programming languages such as C or C++) that these variables are assigned to specific categories. These categories are what we refer to as the data type.

Data types are a very important concept available in almost all programming languages. As the name indicates, a data type represents a specific kind of data that can be processed using your computer program. Learn about the various data types of Python.

In contrast to other programming languages such as C, the variables are not simply declared as some R data type, but assigned with R objects. The data type of the R object becomes the data type of the variable. There are several types of R objects most common being:

  1. Vectors
  2. Matrices
  3. Lists
  4. Arrays
  5. Factors
  6. Data Frames

Vectors are the most basic R data types holding elements of different classes. There are five major data types of these atomic vectors. The other R-Objects are built upon the atomic vectors.

Learn data science courses from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Mentioned below are some of the R data types used in creating vectors:

Top R Data Types

1. Numeric Data Type

In R programming language, decimal values are called numerics. It is the default R data type assigned to all values in R. Let us understand it with the help of an example:

> y = 11.6 # assigns a decimal value to y variable

> y # prints the value of y

[1] 11.6

> class(y) # prints the class name of y 

[1] “numeric”

Here, decimal value (11.6) has been assigned to a variable “y”, whose data type is numeric by default.

Even if you give the variable a non-decimal value, its default data type will still be numeric and not an integer. Here is an example for you:

> y = 1 

> y # print the value of y variable

[1] 1 

> class(y) # print the class name of y

[1] “numeric”

Read: Variables and Data Types in Python [An Ultimate Guide for Developers]

2. Integer Data Type

Numbers without the decimal values are declared under the data type integer in R programming language. To create an integer variable in R, the integer function is revoked. Also, is.integer function can be applied to ensure that y is indeed an integer. Let us look at a few examples to understand the integer data type:

> x = as.integer(5) 

> x # print the value of x 

[1] 5

> class(x)       

[1] “integer” 

> is.integer(x) # function to ensure if x is an integer or not

[1] TRUE

Another way to declare an integer is by appending an L suffix.

> x = 5L 

> is.integer(x) # function to ensure if x is an integer or not 

[1] TRUE

A value with numeric data type can be coerced into an integer data type with as.integer function.

> as.integer(7.16) # coercing a numeric value 

[1] 7

A string with decimal values can also be parsed using the as.integer function.

> as.integer(“7.16”) # coercing a decimal string 

[1] 7

However, it would be wrong to parse a non-decimal string to the integer function. 

Checkout: MATLAB Data Types

3. Complex Data Type 

A complex value in the R programming language is defined via the pure imaginary value i.

> k = 1 + 2i # creating a complex number 

> k            

[1] 1+2i 

> class(k)     

[1] “complex”

4. Logical Data Type

The logical data types in R take either true or false value. This value is generated after comparing the two values. Mentioned below is an example for you:

> l = 4; m = 2   

> n = l > m # is l larger than y? 

> n # printing t the logical value 

[1] TRUE 

> class(n) # printing the class name of z 

[1] “logical”

Explore our Popular Data Science Online Courses

5. Character Data Type 

A character data type is used to represent string values in the R Programming language. Objects are converted into character values using the as.character () function. Mentioned below are some example to built a clear understanding of character data type: 

> y = as.character(7.16) 

> y # print the character string 

[1] “7.16” 

> class(y) # print the class name of y 

[1] “character”

To concatenate two character values, a paste function can be used. 

> fname = “Riya”; lname =”Sharma” 

> paste(fname, lname) 

[1] “Riya Sharma”

Now, since you have developed an understanding of the most common data types, let us look at how we can create vector objects and use the data types to declare values. 

A vector is a set of data elements of the same type of data. 

Given below is a vector containing three numeric values 4, 5, and 6.

> c(4, 5, 6) 

[1] 4 5 6

And here is a vector of logical values.



A vector can also contain character strings.

> c(“AA”, “BB”, “CC”, “DD”, “EE”) 

[1] “AA” “BB” “CC” “DD” “EE”

Other R Objects


Creates a two-dimensional data set. Here is an example: 

Create a matrix.

M = matrix( c(‘q’,’w’,’e’,’r’,’t’,’y’), nrow = 2, ncol = 3, byrow = TRUE)


Output –  

     [,1] [,2] [,3]

[1,] “q” “w” “e” 

[2,] “r” “t” “y”


A list is a type of object containing different types of elements: vectors, functions, and even other lists.


#Create a list containing vectors and numeric values.

list1 <- list(c(2,5,3),7.9)

# Print the list.


Output – 


[1] 2 5 3


[1] 7.9


Unlike matrices, arrays can be of n dimensions. The dim attribute used in arrays creates the required number of dimensions. Mentioned below is an example to create an array with two elements with 2X2 matrices.

 Create an array.

a <- array(c(‘pink’,’blue’),dim = c(2,2,1))


When we execute the above code, it produces the following result −

, , 1

     [,1] [,2]    

[1,] “pink” “blue” 

[2,] “blue” “pink”  

Our learners also read: Learn Python Online for Free


Factors are r-objects created using a vector. Factors store the vectors with distinct values of elements in the vector as labels. The labels always have character data type irrespective of data type in the input vector. Factors are extremely useful in carrying out statistical modelling.

Factors can be created using the factor() function. 

# Create a vector.

colors <- c(‘yellow’,’blue’,’pink’)

# Create a factor object.

factor_colors <- factor(colors)

# Print the factor.


[1] yellow blue pink

Data Frames

Data frames are tabular data objects. Each column in a data frame can contain different modes of data. All three columns can have different data types, may it be an integer, numeric, or character. 

Data Frames are created using the data.frame() function.

# Create the data frame.

Data <- data.frame(

   gender = c(“Male”, “Female”), 

   height = c(153, 160), 

   weight = c(80, 78),

   Age = c(40 29)




  gender height weight Age

1 Male 153.0 80 40

2 Female 160.0 78 29  

Also Read: R Developer Salary in India: For Freshers & Experienced

Read our popular Data Science Articles

upGrad’s Exclusive Data Science Webinar for you –

Transformation & Opportunities in Analytics & Insights

Top Data Science Skills to Learn to upskill

What Next?

If you are curious to learn about R, data science, check out our PG Diploma in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.


Rohit Sharma

Blog Author
Rohit Sharma is the Program Director for the UpGrad-IIIT Bangalore, PG Diploma Data Analytics Program.

Frequently Asked Questions (FAQs)

1What are the drawbacks of using the R programming language?

In many respects, R is insecure. This feature is available in most programming languages, including Python. As a result, R has a variety of drawbacks, one of which being its inability to be used in a web application. R is a challenging language to learn. The learning curve is a bit complex. As a result, learning R may be difficult for individuals who have never coded before. R is connected to the S programming language, which is much older. This means that the basic package doesn't support dynamic or 3D graphics.

2What are R variables?

R variables are usually vectors (lists of data) and can be numeric or text. R variables are usually lower-case, and we use the - operator to assign values to them. Use the c function to make a vector and then list the values.


Explore Free Courses

Suggested Blogs

Python Developer Salary in India in 2024 [For Freshers &#038; Experienced]
Wondering what is the range of Python developer salary in India? Before going deep into that, do you know why Python is so popular now? Python has be
Read More

by Sriram

21 May 2024

Binary Tree in Data Structure: Properties, Types, Representation &#038; Benefits
Data structures serve as the backbone of efficient data organization and management within computer systems. They play a pivotal role in computer algo
Read More

by Rohit Sharma

21 May 2024

Data Analyst Salary in India in 2024 [For Freshers &#038; Experienced]
Summary: In this Article, you will learn about Data Analyst Salary in India in 2024. Data Science Job roles Average Salary per Annum Data Scient
Read More

by Shaheen Dubash

20 May 2024

Python Free Online Course with Certification [2024]
Summary: In this Article, you will learn about python free online course with certification. Programming with Python: Introduction for Beginners Le
Read More

by Rohit Sharma

20 May 2024

13 Interesting Data Structure Projects Ideas and Topics For Beginners [2023]
 In the world of computer science, understanding data structures is essential, especially for beginners. These structures serve as the foundation for
Read More

by Rohit Sharma

20 May 2024

Top 30 Python Pattern Programs You Must Know About
Summary Pattern in Python or “Python patterns” is an essential part of Python programming, especially when you are just starting out with using algor
Read More

by Rohit Sharma

19 May 2024

15 Exciting Data Science Project Ideas &#038;  Topics for Beginners [2024]
Summary: In this Article, you will learn about 15 exciting data science project ideas & topics for beginners. 1. Beginner Level | Data Science P
Read More

by Rohit Sharma

16 May 2024

Binary Tree vs Binary Search Tree: Difference Between Binary Tree and Binary Search Tree
Introduction Sorting is the process of arranging the data in a systematic order so that it can be analysed more effectively. The process of identifyi
Read More

by Rohit Sharma

16 May 2024

Top 12 Fascinating Python Applications in Real-World [2024]
It is a well-established fact that Python is one of the most popular programming languages in both the coding and Data Science communities. But have y
Read More

by Rohit Sharma

16 May 2024

Schedule 1:1 free counsellingTalk to Career Expert
footer sticky close icon