For Programming in any language, variables play an important role. Variables are used to reserve the space in memory and then we can utilize it by storing some value in that variable.
The value stored can be of any type. For example, integer, float, double, string, or boolean. All these data types are used to reserve different spaces in memory.
Unlike other programming languages, data types of R language are not same as them. In R language the variables are assigned with R objects and the datatype of R Objects becomes the data type of variable.
Data types in R language are:
 Vectors
 List
 Matrices
 Arrays
 Factors
 Data Frames
The easiest and simplest of these is Vectors. There are 6 subdivisions of the vectors and they are known as atomic vectors, also known as 6 classes of vectors.
Classes of Vectors
Data Types  Example  Verify  
Logical  True, False 
chevron_right
filter_none
Output: "logical" 

Numeric  11, 5.6, 0.99 
chevron_right
filter_none
"numeric" 

Integer  3L, 6L, 10L 
chevron_right
filter_none
Output: "integer" 

Complex  6+i 
chevron_right
filter_none
Output: "complex" 

Character  ‘R’, “Language” 
chevron_right
filter_none
Output: "character" 

Raw  “Hello” is stored as 48 65 6c 6c 6f 
chevron_right
filter_none
Output: "raw" 
Please remember that in the R language the number of classes is not limited to the above types. Utilizing the atomic vectors we can create an array whose class can be further considered to be an array.
Vectors
c()
function is used to combine elements when more than one element is to be used in vector.
# Create a vector. apple <  c( 'geeks' , 'for' , "benefit" ) print (geeks) # Get the class of the vector. print ( class (geeks)) 
Output:
"geeks" "for" "benefit" "character"
List
The list is a kind of R object which can combine more than one element even another list inside it.
# Create a list. list1 <  list (c( 4 , 5 , 6 ), 22.7 , cos) # Print the list. print (list1) 
Output:
[[1]] [1] 4, 5, 6 [[2]] [1] 22.7 [[3]] function (x) .Primitive("cos")
Matrices
It is a data set having twodimension. It can be created using the vector input with the use of matrix()
function.
# Create a matrix. S = matrix(c( 'a' , 'b' , 'c' , 'd' , 'e' , 'f' ), numberOfRow = 2 , numberOfCol = 3 , byRow = TRUE) print (M) 
Output:
[, 1] [, 2] [, 3] [1, ] "a" "b" "c" [2, ] "d" "e" "f"
Arrays
Unlike matrices, arrays can be of multiple dimensions. In array “dim” variables takes the number of dimensions we need to create.
# Create an array. a <  array(c( 'grapes' , 'mango' ), dim = c( 3 , 3 , 2 )) print (a) 
Output:
,, 1 [, 1] [, 2] [, 3] [1, ] "grapes" "mango" "grapes" [2, ] "mango" "grapes" "mango" [3, ] "grapes" "mango" "grapes",, 2 [, 1] [, 2] [, 3] [1, ] "mango" "grapes" "mango" [2, ] "grapes" "mango" "grapes" [3, ] "mango" "grapes" "mango"
Factors
Vectors are used to create factors that are RObjects. Along with the distinct value of elements factors store vectors as labels.
Labels are always a character. factor()
function is used to create factors. nlevel()
function always counts the number of levels.
# Create a vector colors <  c( 'green' , 'green' , 'yellow' , 'red' , 'red' , 'red' , 'green' ) # Create a factor object. factor <  factor(colors) # Print the factor. print (factor) print (nlevels(factor)) 
Output:
[1] green green yellow red red red green Levels: green red yellow [1] 3
Data Frames
Tabular data RObjects are known as data frames. Basically it is kind of the matrix. But unlike matrix, data frames can store different forms of modes. It is a vector having the same length. data.frames()
function is used to create data frames.
# Create the data frame. employee <  data.frame( gender = c( "Male" , "Male" , "Female" ), height = c( 152 , 171.5 , 165 ), weight = c( 81 , 93 , 78 ), Age = c( 42 , 38 , 26 ) ) print (employee) 
Output:
gender height weight Age 1 Male 152.0 81 42 2 Male 171.5 93 38 3 Female 165.0 78 26
Recommended Posts:
 Difference Between Machine Language and Assembly Language
 Difference Between Assembly Language And Machine Language
 Boxplots in R Language
 Finding Day and Month on a Specific Date in R Language  weekday() and month() function
 Histograms in R language
 Introduction to R Programming Language
 Scatter plots in R Language
 Interesting Facts about R Programming Language
 Web Scraping using R Language
 Playing a beep Sound in R Language  beep() Function
 Getting attributes of Objects in R Language  attributes() and attr() Function
 Find Location and Character Vector of an Object with partial name in R Language  apropos() and find() Function
 Case conversion of a String in R Language  toupper(), tolower(), casefold() and cartr() Function
 Modify values of a Data Frame in R Language  transform() Function
 Remove Leading whitespaces from a String in R Language  trimws() Function
 Changing row and column values of a Matrix in R Language  sweep() function
 Rounding off values in R Language  round() Function
 Converting a List to Vector in R Language  unlist() Function
 Job Control Language (JCL) Utilities
 What Are the Tidyverse Packages in R Language?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.