Why does inner_join behave differently for data.table?

I wanted to join a data frame with a data table using dplyrfunction inner_join(). Here are my codes.

library(data.table)
library(dplyr)

DF <- data.frame(x = rep( c("a","b","c"), each=3), 
                 y = rep( c(1,3,6), 3))

DT <- data.table(x = rep( c("a","b","c"), each=3), 
                 y = rep( c(1,3,6), 3))

W <- data.frame(x = c("b","c","d"), 
              foo = c(4,2,9))

When I try to join two data frames, it inner_join()works as expected.

inner_join(DF,W)

Joining by: "x"
  x y foo
1 b 1   4
2 b 3   4
3 b 6   4
4 c 1   2
5 c 3   2
6 c 6   2

But when I try to join a data frame with a data table, inner_join()it gives an unexpected result.

inner_join(DT,W)

Joining by: "x"
  x y foo
1 b 1   2
2 b 3   2
3 b 6   2
4 c 1   9
5 c 3   9
6 c 6   9

Can someone please give me some clues why this is happening? Thanks in advance for your time.

Note. I am using RStudio version 0.98.1056 on MAC Maverick OS X 10.9.4, and sessionInfo()-

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.2        data.table_1.9.2

loaded via a namespace (and not attached):
[1] assertthat_0.1 parallel_3.1.1 plyr_1.8.1     Rcpp_0.11.2    reshape2_1.4  
[6] stringr_0.6.2  tools_3.1.1   
+4
source share
1 answer

, data.table , , . , , Red Herring .

, dplyr v0.2 inner_join.data.table, inner_join.data.frame ( a data.table data.frame).

require(dplyr) ## 0.2 CRAN
require(data.table) ## 1.9.2

methods(inner_join)
# [1] inner_join.data.frame* inner_join.tbl_df*     inner_join.tbl_dt*    
# [4] inner_join.tbl_sql*  

, :

inner_join(DF, W)

inner_join(DT, W)

dplyr's.

, , , DF W x , DT x .

, DF$x :

DF$x = as.character(DF$x)
inner_join(DF, W)
# Joining by: "x"
#   x y foo
# 1 b 1   2
# 2 b 3   2
# 3 b 6   2
# 4 c 1   9
# 5 c 3   9
# 6 c 6   9

, , dplyr.

+5

All Articles