如何使用 sparklyr 计算字符串之间的距离?
How to calculate distance between strings using sparklyr?
我需要使用 sparklyr 计算 R 中两个字符串之间的距离。有没有办法使用 stringdist 或任何其他包?我想使用 cousine 距离。此距离用作 stringdist 函数的方法。
提前致谢。
您可以使用built-in levenshtein
函数:
df <- copy_to(sc, data.frame(a=c("This is it", "Foo"), b=c("This is", "foobar)))
# df %>% mutate(dist = levenshtein(a, b))
# # Source: lazy query [?? x 3]
# # Database: spark_connection
# a b dist
# <chr> <chr> <int>
# 1 This is it This is 3
# 2 Foo foobar 4
我需要使用 sparklyr 计算 R 中两个字符串之间的距离。有没有办法使用 stringdist 或任何其他包?我想使用 cousine 距离。此距离用作 stringdist 函数的方法。
提前致谢。
您可以使用built-in levenshtein
函数:
df <- copy_to(sc, data.frame(a=c("This is it", "Foo"), b=c("This is", "foobar)))
# df %>% mutate(dist = levenshtein(a, b))
# # Source: lazy query [?? x 3]
# # Database: spark_connection
# a b dist
# <chr> <chr> <int>
# 1 This is it This is 3
# 2 Foo foobar 4