R: How to subset multiple elements from a list

后端 未结 1 1702
醉梦人生
醉梦人生 2021-01-07 12:28
    > x
    [[1]]
    [1] \"Bob\"  \"John\" \"Tom\" 
    [2] \"Claire\" \"Betsy\"

    [[2]]
    [1] \"Strawberry\" \"Banana\"    
    [2] \"Kiwi\"

    [[3]]
            


        
相关标签:
1条回答
  • 2021-01-07 13:22

    Try

    sapply(x2, `[`,2)
    #[1] " from localhost (localhost [127.0.0.1])"                   
    #[2] " from phobos [127.0.0.1]"                                  
    #[3] " from n20.grp.scd.yahoo.com (n20.grp.scd.yahoo.com"        
    #[4] " from [66.218.67.196] by n20.grp.scd.yahoo.com with NNFMP;"
    

    data

    x2 <- list(c("Received", " from localhost (localhost [127.0.0.1])"),
     c("Received", " from phobos [127.0.0.1]"), c("Received", 
     " from n20.grp.scd.yahoo.com (n20.grp.scd.yahoo.com"), 
     c("Received", " from [66.218.67.196] by n20.grp.scd.yahoo.com with NNFMP;" ) )
    
    0 讨论(0)
提交回复
热议问题