我需要将data.frame转换为基于dataframe列之一的字符列表。
从两个列的data.frame开始,第一个包含化合物名称的唯一值,而另一个包含非唯一的化合物类型类别。例:
Compound_name Compound_type
A Inhibitor_A
B Inhibitor_B
C Inhibitor_A
D Inhibitor_C
E Inhibitor_B
我想以基于如下所示的化合物类型的列表结尾:
Inhibitor_A 'A' 'C'
Inhibitor_B 'B' 'E'
Inhibitor_C 'C'
我的data.frame包含2000个化合物,所以我需要一种迭代的方法。
我不知道从哪里开始计算这个,非常感谢。
您可以split
像这样使用:
split(x$Compound_name, x$Compound_type)
#$Inhibitor_A
#[1] "A" "C"
#
#$Inhibitor_B
#[1] "B" "E"
#
#$Inhibitor_C
#[1] "D"
数据:
x <- structure(list(Compound_name = c("A", "B", "C", "D", "E"), Compound_type = c("Inhibitor_A",
"Inhibitor_B", "Inhibitor_A", "Inhibitor_C", "Inhibitor_B")), class = "data.frame", row.names = c(NA,
-5L))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句