我只是在寻找使用gsub
的代码,以删除第二个模式"_"
之前的所有文本
我用过:
for (i in 1:length(df1)){
df1[, i]<- gsub("_([^_]**)", "",df1[, i])
}
但是它不起作用;这是我的数据框
query cluster_000001 cluster_000003
1: query cluster_000001_Phycodnaviridae cluster_000003_Baculoviridae
2: query cluster_000001_Phycodnaviridae cluster_000003_Baculoviridae
3: query cluster_000001_Phycodnaviridae cluster_000003_Baculoviridae
4: query cluster_000001_Phycodnaviridae cluster_000003_Baculoviridae
5: query cluster_000001_Phycodnaviridae cluster_000003_Baculoviridae
以及我应该得到的:
query cluster_000001 cluster_000003
1: query Phycodnaviridae Baculoviridae
2: query Phycodnaviridae Baculoviridae
3: query Phycodnaviridae Baculoviridae
4: query Phycodnaviridae Baculoviridae
5: query Phycodnaviridae Baculoviridae
感谢您的帮助