Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Created March 13, 2013 10:22
Show Gist options
  • Save mrdwab/5150850 to your computer and use it in GitHub Desktop.
Save mrdwab/5150850 to your computer and use it in GitHub Desktop.
Recursively determine how deep a list is nested in R
list.depth <- function(this, thisdepth = 0) {
# http://stackoverflow.com/a/13433689/1270695
if(!is.list(this)) {
return(thisdepth)
} else {
return(max(unlist(lapply(this, list.depth, thisdepth = thisdepth+1))))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment