Search⌘ K
AI Features

Solution Review: Vectors and Lists

Explore how to identify recursive data structures in R by using the is.recursive() function, focusing on vectors and lists. Understand the difference between recursive and non-recursive objects and practice printing outputs with cat. This lesson helps you solidify your understanding of key R data structures.

We'll cover the following...

Solution: Using is.recursive()

R
testVariable <- list(1, 1+1i, "a", TRUE)
cat(is.recursive(testVariable))
cat("\n")
testVariable <- c(1, 2, 3, 4)
cat(is.recursive(testVariable))

Explanation

The method is.recursive() with the testVariable can tell us whether the object being passed is recursive or not. Here, list is recursive, while vector is not recursive. Later, we can print using cat().