我的数据如下:
df <- structure(list(V1 = structure(c(7L, 4L, 8L, 8L, 5L, 3L, 1L, 1L,
2L, 1L, 6L), .Label = c("", "cell and biogenesis;transport",
"differentiation;metabolic process;regulation;stimulus", "MAPK cascade;cell and biogenesis",
"MAPK cascade;cell and biogenesis;transport", "metabolic process;regulation;stimulus;transport",
"mRNA;stimulus;transport", "targeting"), class = "factor")), .Names = "V1", class = "data.frame", row.names = c(NA,
-11L))
我想要计算有多少相似的字符串,并记录它们来自哪一行。每个字符串用分号
;
分隔,但它们属于它们所在的行。我希望输出结果如下:
String Count position
mRNA 1 1
stimulus 3 1,6,11
transport 4 1,5,9,11
MAPK cascade 2 2,5
cell and biogenesis 3 2,5,9
targeting 2 3,4
regulation of mRNA stability 1 1
regulation 2 6,11
differentiation 1 6,11
metabolic process 2 6,11
这个计数显示了整个数据中每个字符串(这些字符串由分号分隔)被重复的次数。 第二列显示它们所在的位置,例如mRNA只出现在第一行,因此为1。刺激物在第1行、第6行和第11行都有出现,因此为1、6和11。
一些行是空白的,但它们也被计算为行。