簡體   English   中英

從data.frames列表中設置子插槽

[英]Subsetting slot from a list of data.frames

我想從注釋過程產生的以下列表中提取行:“ 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")) 

最好

怎么樣:

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函數之間的區別。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM