Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

Heterogeneous Data in R

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Data structures are a logical way or representing as per requirement. They further help depict this logical view physically in computer memory. In the R language, data structures can be classified into two groups, namely homogeneous and heterogeneous.

  • Homogeneous Data Structures: This type can only store a single type of data inside them(integer, character, etc.),
  • Heterogeneous Data Structures: This type can store more than one type of data at the same time.

Heterogeneous Data Structures

R supports two ways of representing heterogeneous data, namely lists and dataframe. Both structures are discussed in detail below:

1) Lists :

  • Lists are single-dimensional heterogeneous data types.
  • A list can represent more than one data type at a time.
  • We can simply use the list() function to create a list.
  • Lists are similar to vectors, however, vectors are homogeneous and lists are heterogeneous.
  • Another interesting property of lists is that we can store lists inside other lists(like simple recursion). Due to this reason, Lists are also referred to as “Recursive Vectors“.



list_ex = list(Ch="R language", numbers = 5:1, fl=FALSE)



[1] “R language”


[1]  5 4 3 2 1



Example: Recursive vectors


list_ex2<-list(list(1,"R language",FALSE), list("Python",2,"Language"),


List of 3

$ :List of 3

 ..$ : num 1

 ..$ : chr “R language”

 ..$ : logi FALSE

$ :List of 3

 ..$ : chr “Python” 

 ..$ : num 2

 ..$ : chr “Language”

$ :List of 3

 ..$ : chr “Hello”

 ..$ : logi FALSE

 ..$ : chr “World”          

2) Data Frames:

  • In the R language, a data frame is a two-dimensional heterogeneous table-like structure
  • They are simply lists of vectors that have equal lengths.
  • Data frames make data analysis easier when they are used systematically,
  • In the R language, we use the data.frames() function to create data frames.
  • A data frame in R must follow the following rules :
    • A data frame must have column names and each column must contain equal amount of items,
    • Each row in a data frame must have a unique name,
    • Each entry in a column must have same data type,
    • Different columns can have same or different data types.



employee_id <- c(1:4)
employee_name <- c("Abdul", "Anshul", "Vishal", "Riya")
employee_salary <- c("45000", "90000", "25000", "75000")
employee_designation <- c("Software Engineer", "Senior Manager", "Intern","Manager") <- data.frame(employee_id , employee_name, employee_salary,


My Personal Notes arrow_drop_up
Last Updated : 24 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials