【问题标题】:create distance matrix from string column in dataframe从数据框中的字符串列创建距离矩阵
【发布时间】:2019-05-02 12:45:35
【问题描述】:

我尝试使用此代码但没有成功:

library(fuzzywuzzyR)
library(proxy)

set.seed(42)
rm(list = ls())
options(scipen = 999)

init = FuzzMatcher$new()

data <- data.frame(string = c("aaaaa baaaaa", "baaaaa xxxhhx ", "caaaaa hhhr ejhhehe"))
data$string <- as.character(data$string)

f <- function(string_1, string_2) {
    init$Token_set_ratio(string1 = string_1, string2 = string_2, force_ascii = TRUE, full_process = TRUE)
}

proxy::dist(data$string, method = f)

目的是使用 proxy::dist 和fuzzywuzzyR 包生成每一行之间的距离。

错误:

错误:参数“string1”和“string2”都应该是类型 字符串 另外:警告信息: 在 do.call(".External", c(list(CFUN, x, y, pairwise, if (!is.function(method)) get(method) else method), 中: 强制引入的 NAs

【问题讨论】:

  • 哪里失败了?
  • 为什么是近距离投票?!!!这是一个完全可重现的问题?!老实说,这些天很痛苦....
  • 第 1 步:确保您的 string 设置为字符(不是因素)
  • mmh - as.character 有什么作用?你试过运行这个吗?
  • as.character 正是这样做的,但错误表明它们不是字符。不,我没有运行它。

标签: r


【解决方案1】:

我在我的机器上对此进行了测试,并通过 install.packages 安装了fuzzywuzzyr 包。这很好地安装了包,但是当我运行init$Token_set_ratio(string1 = s1, string2 = s2, force_ascii = TRUE, full_process = TRUE) 时,这给了我一个attempt to apply non-function 的错误,这反过来又在稍后对proxy::dist 的调用中返回NAs introduced by coercion。我相信问题可能类似于https://github.com/mlampros/fuzzywuzzyR/issues/4,我什至无法运行小插图中的基本示例。我相信该软件包已损坏或未维护,因为我什至无法运行 github repo 中的 utils 部分而不会出现相同的非功能错误。抱歉,这无法解决您的问题,但也许会有所帮助。

【讨论】:

  • 供您参考,“尝试应用非功能”错误意味着您没有正确的 Python 配置,或者您的操作系统中未安装所需的 Python 包之一。命令 'reticulate::py_discover_config()' 和 'reticulate::py_module_available('fuzzywuzzy')' 可能会给你一些正确方向的提示。
最近更新 更多