Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

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

By Rohit Sharma

Updated on Nov 25, 2022 | 7 min read

Share:

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”

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.

> c(FALSE TRUE FALSE TRUE) 

[1] FALSE TRUE FALSE TRUE

A vector can also contain character strings.

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

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

Other R Objects

Matrices

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)
print(M)
Output –  
     [,1] [,2] [,3]
[1,] “q” “w” “e” 
[2,] “r” “t” “y”

Lists

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

Example

#Create a list containing vectors and numeric values.
list1 <- list(c(2,5,3),7.9)
# Print the list.
print(list1)
Output – 
[[1]]
[1] 2 5 3
[[2]]
[1] 7.9

Arrays

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))
print(a)
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

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.
print(factor_colors)
[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)
)
print(BMI)
Output

  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

upGrad’s Exclusive Data Science Webinar for you –

Transformation & Opportunities in Analytics & Insights

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.

Frequently Asked Questions (FAQs)

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

2. What are R variables?

Rohit Sharma

601 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

Start Your Career in Data Science Today

Suggested Blogs