Access lapply index names inside FUN

前端 未结 12 2288
自闭症患者
自闭症患者 2020-11-22 15:04

Is there a way to get the list index name in my lapply() function?

n = names(mylist)
lapply(mylist, function(list.elem) { cat(\"What is the name of this list         


        
12条回答
  •  自闭症患者
    2020-11-22 15:24

    Just loop in the names.

    sapply(names(mylist), function(n) { 
        doSomething(mylist[[n]])
        cat(n, '\n')
    }
    

提交回复
热议问题