Determine level of nesting in R?

后端 未结 3 1807
既然无缘
既然无缘 2020-12-02 21:31

Is there an easy way (i.e. a function) to determine the level of nesting in list? I know there is str which can be used to get this information. But is there so

3条回答
  •  佛祖请我去吃肉
    2020-12-02 21:50

    If all elements are named, you could use this (from the code of unlist):

    mylist <- list(a=list(x=1),b=list(c=list(y=c(2,3)),d=c("a","b")))
    names(.Internal(unlist(mylist, TRUE, TRUE)))
    #[1] "a.x"    "b.c.y1" "b.c.y2" "b.d1"   "b.d2" 
    

提交回复
热议问题