2013-02-09 11 views
8
sample <- 
structure(list(GB05 = structure(c(22L, 34L, 26L, 2L), .Dim = 4L, .Dimnames = structure(list(
    c("98", "100", "102", "106")), .Names = ""), class = "table"), 
    GB18 = structure(c(8L, 14L, 70L), .Dim = 3L, .Dimnames = structure(list(
     c("173", "175", "177")), .Names = ""), class = "table"), 
    GB06 = structure(c(2L, 16L, 48L, 10L, 10L, 6L), .Dim = 6L, .Dimnames = structure(list(
     c("234", "238", "240", "242", "244", "246")), .Names = ""), class = "table"), 
    GB27 = structure(c(2L, 28L, 2L, 2L, 4L, 3L, 2L, 2L, 15L, 
    17L, 4L, 5L), .Dim = 12L, .Dimnames = structure(list(c("145", 
    "147", "149", "151", "156", "159", "165", "167", "169", "171", 
    "173", "175")), .Names = ""), class = "table"), GB24 = structure(c(2L, 
    4L, 41L, 10L, 6L, 2L, 14L, 2L, 3L), .Dim = 9L, .Dimnames = structure(list(
     c("240", "241", "242", "243", "244", "247", "249", "251", 
     "253")), .Names = ""), class = "table"), GB28 = structure(c(30L, 
    22L, 2L, 10L, 2L, 4L, 2L, 2L, 2L), .Dim = 9L, .Dimnames = structure(list(
     c("363", "364", "365", "367", "371", "377", "380", "384", 
     "390")), .Names = ""), class = "table"), GB15 = structure(c(12L, 
    16L, 43L, 2L, 3L, 4L), .Dim = 6L, .Dimnames = structure(list(
     c("142", "144", "146", "147", "148", "152")), .Names = ""), class = "table"), 
    GB02 = structure(c(6L, 78L, 4L), .Dim = 3L, .Dimnames = structure(list(
     c("194", "197", "200")), .Names = ""), class = "table"), 
    GB10 = structure(c(2L, 36L, 7L, 1L, 16L, 20L), .Dim = 6L, .Dimnames = structure(list(
     c("124", "126", "128", "130", "132", "134")), .Names = ""), class = "table"), 
    GB14 = structure(c(3L, 6L, 7L, 37L, 7L), .Dim = 5L, .Dimnames = structure(list(
     c("181", "184", "187", "193", "196")), .Names = ""), class = "table")), .Names = c("GB05", 
"GB18", "GB06", "GB27", "GB24", "GB28", "GB15", "GB02", "GB10", 
"GB14")) 

このlapply呼び出しでプロットタイトルとして表示されるリストの名前を取得するにはどうすればよいですか(各プロットごとに1つのタイトル)?lapplyの呼び出しでプロットタイトルとしてリスト名を追加するR

dev.new() 
par(mfrow=c(2,5)) 
lapply(sample,function(x) plot(x,main=names[x])) 

なぜmain = names [x]が機能しないのか分かりません。 を表示するには

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

enter image description here

はあなたの名前を取得されていませんなぜ、実行lapply(afn, function(x) names(x))はあなたに名それぞれのを与える:代わりに、リスト項目の名前に

+0

あなたの 'dput'出力は正しくコピー/ペーストされません。コピーしようとするとエラーが発生します。 – Arun

+0

@Arun修正しました。これを指摘してくれてありがとうございます。 – Chargaff

+1

@Chargaff、nope。 *今は*修正されました。最初の行は 'sample < - dput(afn)'です。その 'dput(afn)'部分を含める必要はありません。 – A5C1D2H2I1M1N2O1R2T1

答えて

14

使用lapplyリスト項目などlapply(names(afn), function(x) x)と同じように試して、その違いを比較してください。次に、[[を使用して単一のリスト項目を名前で抽出できることを忘れないでください。

+0

$ name_plotを使ってアクセスするには、ここで 'sapply'を使います... – agstudy

関連する問題