Check if the Object is a List in R Programming – is.list() Function

is.list() function in R Language is used to return TRUE if the specified data is in the form of list, else returns FALSE.

Syntax: is.list(X)

Parameters:
x: different types of data storage

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# is.list function
  
# Initializing some list
a <- list(1, 2, 3)
b <- list(c("Jan", "Feb", "Mar"))
c <- list(matrix(c(1, 2, 3, 4, 5)))
d <- list(list("green", 12.3))
  
# Calling is.list() function
is.list(a)
is.list(b)
is.list(c)
is.list(d)

chevron_right


Output:

[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# is.list function
  
# Initializing a data frame "Biochemical Oxygen
# Data" data sets
x <- BOD
  
# Each row of the data frame is a list 
a <- x[2, ]
  
# Each column of the data frame is not a list 
b <- x[, 1]
  
# Calling is.list() function
is.list(a)
is.list(b)

chevron_right


Output:

[1] TRUE
[1] FALSE



My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.