Adding lists names as plot titles in lapply call in R

前端 未结 1 498
粉色の甜心
粉色の甜心 2020-12-09 11:49
sample <- 
structure(list(GB05 = structure(c(22L, 34L, 26L, 2L), .Dim = 4L, .Dimnames = structure(list(
    c(\"98\", \"100\", \"102\", \"106\")), .Names = \"\"),         


        
相关标签:
1条回答
  • 2020-12-09 12:23

    Use lapply on the names of the list items instead:

    lapply(names(afn), function(x) plot(afn[[x]], main=x))
    

    enter image description here

    To see why you aren't getting your names, run lapply(afn, function(x) names(x)) gives you the names of each list item or something else. Try the same with lapply(names(afn), function(x) x) and compare the difference. Then, remember that we can extract a single list item by name by using [[.

    0 讨论(0)
提交回复
热议问题