【发布时间】:2022-12-10 22:18:18
【问题描述】:
我有以下名为 df 的数据框(dput 下面):
group string
1 1 Bc
2 1 EPc
3 1 Lkc
4 2 ABR
5 2 mA
6 2 Amt
7 3 Yrt
8 3 rtU
9 3 rti
我想找到出现在每组所有字符串中的字符。例如组 1 在每个字符串中都有字符 c。这是所需的输出:
group similar
1 1 c
2 2 A
3 3 rt
所以我想知道是否有人知道如何在 R 中的每个组的每个字符串中找到相似的字符?
dputdf:
df <- structure(list(group = c("1", "1", "1", "2", "2", "2", "3", "3",
"3"), string = c("Bc", "EPc", "Lkc", "ABR", "mA", "Amt", "Yrt",
"rtU", "rti")), class = "data.frame", row.names = c(NA, -9L))
【问题讨论】: