使用StringDist_join与不同的列名称

发布于 2025-01-21 16:45:02 字数 778 浏览 0 评论 0原文

我的示例数据如下:

library(fuzzyjoin)
a <- data.frame(x = c("season", "season", "season", "package", "package"), y = c("1","2", "3", "1","6"))


b <- data.frame(x = c("season", "seson", "seson", "package", "pakkage"), w = c("1","2", "3", "2","6"))

c <- data.frame(z = c("season", "seson", "seson", "package", "pakkage"), w = c("1","2", "3", "2","6"))

因此,以下运行良好:

d <- stringdist_left_join(a,b, by = "x", max_dist = 2)

但是不允许使用带有不同名称的列合并(请注意,联接是a and c) 。

e <- stringdist_left_join(a,c, by = c("x", "z"), max_dist = 2)

我想告诉stringdist_left_join使用两个不同的列名来加入,例如代码的最后一行(e) ,但似乎不接受它。

是否有任何解决方案(除了复制列并给它另一个名称)吗?

I have example data as follows:

library(fuzzyjoin)
a <- data.frame(x = c("season", "season", "season", "package", "package"), y = c("1","2", "3", "1","6"))


b <- data.frame(x = c("season", "seson", "seson", "package", "pakkage"), w = c("1","2", "3", "2","6"))

c <- data.frame(z = c("season", "seson", "seson", "package", "pakkage"), w = c("1","2", "3", "2","6"))

So the following runs fine:

d <- stringdist_left_join(a,b, by = "x", max_dist = 2)

But merging with a column with a different name is not allowed (note that the join is now a and c).

e <- stringdist_left_join(a,c, by = c("x", "z"), max_dist = 2)

I would like to tell stringdist_left_join to use two different column names to join by, like the last line of code it (e), but it does not seems to accept it.

Is there any solution to this (other than copying the column and giving it another name)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2025-01-28 16:45:02

您可以将=用于两个不同的列名。您可以使用以下代码:

e <- stringdist_left_join(a,c, by = c("x" = "z"), max_dist = 2)

输出:

         x y       z w
1   season 1  season 1
2   season 1   seson 2
3   season 1   seson 3
4   season 2  season 1
5   season 2   seson 2
6   season 2   seson 3
7   season 3  season 1
8   season 3   seson 2
9   season 3   seson 3
10 package 1 package 2
11 package 1 pakkage 6
12 package 6 package 2
13 package 6 pakkage 6

You can use = for two different column names. You can use the following code:

e <- stringdist_left_join(a,c, by = c("x" = "z"), max_dist = 2)

Output:

         x y       z w
1   season 1  season 1
2   season 1   seson 2
3   season 1   seson 3
4   season 2  season 1
5   season 2   seson 2
6   season 2   seson 3
7   season 3  season 1
8   season 3   seson 2
9   season 3   seson 3
10 package 1 package 2
11 package 1 pakkage 6
12 package 6 package 2
13 package 6 pakkage 6
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文