从data.frames列表中设置插槽

时间:2014-07-07 13:08:43

标签: r

我想提取这一行:" miRFamily"从注释过程产生的以下列表:

List of 3    
 $ 87   :Formal class 'targetscanTarget' [package "targetscan.Hs.eg.db"] with 7 slots     
 .. ..@ miRFamily: chr [1:18] "miR-218/218a" "miR-218/218a" "miR-218/218a" "miR-384/384-3p"    
 .. ..@ UTRstart : int [1:18] 331 331 331 318 318 318 224 224 224 157 ...    
 .. ..@ UTRend   : int [1:18] 338 338 338 324 324 324 230 230 230 163 ...     
 .. ..@ MSAstart : int [1:18] 701 701 701 688 688 688 535 535 535 363 ...     
 .. ..@ MSAend   : int [1:18] 708 708 708 694 694 694 541 541 541 369 ...     
 .. ..@ Seedmatch: chr [1:18] "8mer" "8mer" "8mer" "7mer-1a" ...     
 .. ..@ PCT      : chr [1:18] "0.77" "0.77" "0.77" "NULL" ...      
$ 6876 :Formal class 'targetscanTarget' [package "targetscan.Hs.eg.db"] with 7 slots
 .. ..@ miRFamily: chr [1:6] "miR-485-5p/1698/1703/1962" "miR-485-5p/1698/1703/1962"            "miR-539/539-5p" "miR-539/539-5p" ...      
 .. ..@ UTRstart : int [1:6] 170 170 427 427 149 149         
 .. ..@ UTRend   : int [1:6] 177 177 433 433 155 155             
 .. ..@ MSAstart : int [1:6] 183 183 605 605 157 157            
 .. ..@ MSAend   : int [1:6] 199 199 630 630 163 163               
 .. ..@ Seedmatch: chr [1:6] "8mer" "8mer" "7mer-1a" "7mer-1a" ...                
 .. ..@ PCT      : chr [1:6] "NULL" "NULL" "NULL" "NULL" ...              
$ 10398:Formal class 'targetscanTarget' [package "targetscan.Hs.eg.db"] with 7 slots                
 .. ..@ miRFamily: chr [1:2] "miR-491-5p" "miR-491-5p"                
 .. ..@ UTRstart : int [1:2] 391 391                                 
 .. ..@ UTRend   : int [1:2] 398 398                 
 .. ..@ MSAstart : int [1:2] 577 577                   
 .. ..@ MSAend   : int [1:2] 598 598                   
 .. ..@ Seedmatch: chr [1:2] "8mer" "8mer"                    
  .. ..@ PCT      : chr [1:2] "NULL" "NULL"                 

有人能帮帮我吗?

dput(miRNA_annotation)
  structure(list(`87` = <S4 object of class structure("targetscanTarget", package =     "targetscan.Hs.eg.db")>, 
 `6876` = <S4 object of class structure("targetscanTarget", package = "targetscan.Hs.eg.db")>, 
`10398` = <S4 object of class structure("targetscanTarget", package = "targetscan.Hs.eg.db")>), .Names = c("87", 
"6876", "10398"))

最佳

1 个答案:

答案 0 :(得分:1)

怎么样:

get_miRFamily <- function(my_list){return(my_list@miRFamily)}
lapply(my_list, get_miRFamily)

列表上的测试用例:

get_miRFamily_test <- function(my_list){return(my_list$miRFamily)}
list1 <- list(miRFamily = 5, y = 6)
list2 <- list(miRFamily = 7, z  = 'ad')
y <- list('5' = list1, '80' = list2)
lapply(y, get_miRFamily_test)

应该产生:

$`5`
[1] 5

$`80`
[1] 7

请注意,您必须使用@而不是$来表示您的数据。这也是get_miRFamily和get_miRFamily_test函数之间的区别。