【问题标题】:Removing elements based on a partial string match between 2 data frames:根据 2 个数据帧之间的部分字符串匹配删除元素:
【发布时间】:2018-03-02 00:35:09
【问题描述】:

假设我有两个元素中包含字符串的数据框:

B <- data.frame(c("abcd1","cdbax2","acdb3"))
colnames(B) <- "Strings"

A <- data.frame(c("abcd_11","cdba_12"))
colnames(A) <- "Strings"

产生一对数据帧,

> A
  Strings
1    abcd_11
2    cdba_12

> B
  Strings
1   abcd1
2   cdbax2
3   acdb3

期望的输出:B*, B 清除了不在 A 中的部分字符串:

> B*
      Strings
    1   abcd1
    2   cdbax2

任何想法将不胜感激。

干杯

编辑:基于字符串长度的解决方案不起作用,因为数据帧中可能有不同的长度

【问题讨论】:

    标签: r string pattern-matching


    【解决方案1】:
     B[max.col(-adist(A$Strings,B$Strings)),]
    [1] abcd1  cdbax2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-22
      • 2020-11-28
      • 1970-01-01
      • 2016-04-08
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      相关资源
      最近更新 更多