У меня есть кадр данных (df3) и список списков (l3):
l1<-c("GO:0071363", "GO:0070848", "GO:0007169", "GO:0007167")
l2 <-c("GO:0016567", "GO:0070647", "GO:0032446")
l3 <- list(l1,l2)
names(l3) <- c("GROUP1","GROUP2")
##############################print my list
> l3
$GROUP1
[1] "GO:0071363" "GO:0070848" "GO:0007169" "GO:0007167"
$GROUP2
[1] "GO:0016567" "GO:0070647" "GO:0032446"
############################# ############################
df1 <- structure(list(geneSet = c("GO:0070848", "GO:0071363", "GO:0007169",
"GO:0007167"), description = c("response to growth factor", "cellular response to growth factor stimulus",
"transmembrane receptor protein tyrosine kinase signaling pathway",
"enzyme linked receptor protein signaling pathway")), row.names = c(10L,
16L, 177L, 219L), class = "data.frame")
df2 <- structure(list(geneSet = c("GO:0070647", "GO:0016567", "GO:0032446"
), description = c("protein modification by small protein conjugation or removal",
"protein ubiquitination", "protein modification by small protein conjugation"
)), row.names = c(13L, 15L, 25L), class = "data.frame")
df3 <- rbind(df1,df2)
######################print my dataframe
> df3
geneSet description
10 GO:0070848 response to growth factor
16 GO:0071363 cellular response to growth factor stimulus
177 GO:0007169 transmembrane receptor protein tyrosine kinase signaling pathway
219 GO:0007167 enzyme linked receptor protein signaling pathway
13 GO:0070647 protein modification by small protein conjugation or removal
15 GO:0016567 protein ubiquitination
25 GO:0032446 protein modification by small protein conjugation
Сначала мне нужно сопоставить каждую строку, расположенную в моем столбце geneSet с этой же строкой в списке списков. После этого мне нужно создать дополнительный столбец в моем исходном df3 (названный «cluster»), который содержит имя каждого списка, который содержит соответствующий набор GeneSet. Мой вывод будет:
> df3
geneSet description cluster
10 GO:0070848 response to growth factor GROUP1
16 GO:0071363 cellular response to growth factor stimulus GROUP1
177 GO:0007169 transmembrane receptor protein tyrosine kinase signaling pathway GROUP1
219 GO:0007167 enzyme linked receptor protein signaling pathway GROUP1
13 GO:0070647 protein modification by small protein conjugation or removal GROUP2
15 GO:0016567 protein ubiquitination GROUP2
25 GO:0032446 protein modification by small protein conjugation GROUP2