What is the is.list() function in R?

Overview

The is.list() function in R returns a logical value, TRUE or FALSE, that indicates whether an argument passed to it is a list.

To understand what a list in R is, we can check out this shot.

Syntax

is.list(x)
Syntax for the is.list() function in R

Parameter value

The is.list() function takes a single parameter value, x. This represents the R object to be checked.

Return value

The is.list() function returns a logical value (TRUE or FALSE).

Code example

# Creating R objects
Height1 <- factor(c("Tall", "Average", "Short"))
Height2 <- list(c("Tall", "Average", "Short"))
# Testing if the object are lists
is.list(Height1)
is.list(Height2)

Code explanation

  • Line 2: We create an R object Height1 using the factor() function.
  • Line 3: We create another R object Height2 using the list() function.
  • Line 6: We check whether Height1 is a list by using the is.list() function.
  • Line 7: We check whether Height2 is a list by using the is.list() function.

    Free Resources