How to extract elements from a list with mixed elements

前端 未结 3 1489
北海茫月
北海茫月 2020-12-24 06:27

I have a list in R with the following elements:

[[812]]
[1] \"\"             \"668\"          \"12345_s_at\" \"667\"          \"4.899777748\" 
[6] \"49.53333         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-24 07:05

    In case you wanted to use the code you typed in your question, below is the fix:

    listdata <- list(c("","668","12345_s_at","667", "4.899777748","49.53333333",
           "10.10930207", "1.598228663","5.087437057"),
         c("","376", "6789_at",  "375",  "4.899655078","136.3333333",
           "27.82508792", "2.20223398",  "5.087437057"),
         c("", "19265", "12351_s_at", "19264", "4.897730912",
           "889.3666667", "181.5874908","1.846451572","5.087437057" ))
    
    v <- character() #creates empty character vector
    list_len <- length(listdata)
    for(i in 1:list_len)
        v <- c(v, listdata[[i]][3]) #fills the vector with list elements (not efficient, but works fine)
    
    print(v)
    [1] "12345_s_at" "6789_at"    "12351_s_at"
    

提交回复
热议问题