Learn R Programming

collapse (version 1.1.0)

ldepth: Determine the Depth / Level of Nesting of a List

Description

ldepth provides the depth of a list or list-like structure.

Usage

ldepth(l, DF.as.list = TRUE)

Arguments

l

a list.

DF.as.list

treat data.frame's as sub-lists?

Value

A single integer indicating the depth of the list.

Details

The depth or level or nesting of a list or list-like structure (i.e. a classed object) is found by recursing down to the bottom of the list and adding an integer count of 1 for each level passed. For example the depth of a data.frame is 1. If a data.frame has list-columns, the depth is 2. However for reasons of efficiency, if l is not a data.frame and DF.as.list = TRUE, data.frame's found inside l will not be checked for list column's but assumed to have a depth of 1.

See Also

is.unlistable, has_elem, List Processing, Collapse Overview

Examples

Run this code
# NOT RUN {
l = list(1, 2)
ldepth(l)
l = list(1, 2, mtcars)
ldepth(l)
ldepth(l, DF.as.list = FALSE)
l = list(1, 2, list(4, 5, list(6, mtcars)))
ldepth(l)
ldepth(l, DF.as.list = FALSE)
# }

Run the code above in your browser using DataLab