Inner_join输出灰烬dataframe
我有两个数据帧,我试图将其合并在一起。
df1
PlayerName Date playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI
1: Sandy Alcantara 2022-04-26 18684 @WSN MIA A 6.0 6 1 1 0 3 0 0 0 5 1.0304
2: Sandy Alcantara 2022-04-20 18684 STL MIA H 8.0 4 0 0 0 1 0 0 0 6 2.2004
3: Sandy Alcantara 2022-04-14 18684 PHI MIA H 6.1 7 2 2 0 1 0 0 0 5 1.1064
4: Sandy Alcantara 2022-04-08 18684 @SFG MIA A 5.0 3 3 2 1 5 0 0 0 4 0.2488
df2
Date PlayerName GIDP
1 2022-04-14 Alcantara, Sandy 1
2 2022-04-20 Alcantara, Sandy 1
3 2022-04-26 Alcantara, Sandy 2
在使用内部加入时,输出是一个空的数据框架。
game_logs <- inner_join(df1, df2, by = c("PlayerName", "Date"))
[1] Date PlayerName GIDP playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI
<0 rows> (or 0-length row.names)
我想实现的是看起来像DF3的东西
df1
PlayerName Date playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI GIDP
1: Sandy Alcantara 2022-04-26 18684 @WSN MIA A 6.0 6 1 1 0 3 0 0 0 5 1.0304 2
2: Sandy Alcantara 2022-04-20 18684 STL MIA H 8.0 4 0 0 0 1 0 0 0 6 2.2004 1
3: Sandy Alcantara 2022-04-14 18684 PHI MIA H 6.1 7 2 2 0 1 0 0 0 5 1.1064 1
4: Sandy Alcantara 2022-04-08 18684 @SFG MIA A 5.0 3 3 2 1 5 0 0 0 4 0.2488 NA
I have two data frames that I am trying to merge together.
df1
PlayerName Date playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI
1: Sandy Alcantara 2022-04-26 18684 @WSN MIA A 6.0 6 1 1 0 3 0 0 0 5 1.0304
2: Sandy Alcantara 2022-04-20 18684 STL MIA H 8.0 4 0 0 0 1 0 0 0 6 2.2004
3: Sandy Alcantara 2022-04-14 18684 PHI MIA H 6.1 7 2 2 0 1 0 0 0 5 1.1064
4: Sandy Alcantara 2022-04-08 18684 @SFG MIA A 5.0 3 3 2 1 5 0 0 0 4 0.2488
df2
Date PlayerName GIDP
1 2022-04-14 Alcantara, Sandy 1
2 2022-04-20 Alcantara, Sandy 1
3 2022-04-26 Alcantara, Sandy 2
While using inner join the output is an empty dataframe.
game_logs <- inner_join(df1, df2, by = c("PlayerName", "Date"))
[1] Date PlayerName GIDP playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI
<0 rows> (or 0-length row.names)
What I am trying to achieve is something that looks like df3
df1
PlayerName Date playerid Opp Team HomeAway IP H R ER HR BB IBB WP BK SO exLI GIDP
1: Sandy Alcantara 2022-04-26 18684 @WSN MIA A 6.0 6 1 1 0 3 0 0 0 5 1.0304 2
2: Sandy Alcantara 2022-04-20 18684 STL MIA H 8.0 4 0 0 0 1 0 0 0 6 2.2004 1
3: Sandy Alcantara 2022-04-14 18684 PHI MIA H 6.1 7 2 2 0 1 0 0 0 5 1.1064 1
4: Sandy Alcantara 2022-04-08 18684 @SFG MIA A 5.0 3 3 2 1 5 0 0 0 4 0.2488 NA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在DF2中重新排列名称:
You need to rearrange names in df2: