DT1 <- data.table(product = c("P1","P2","P3"), foo = 1:6)
DT2 <- data.table(product = c("P1","P2","P3"), family = c("A","A","B"))
DT1[DT2,.(product, family), on = "product", by = .EACHI]
gives:
product product family
1: P1 P1 A
2: P2 P1 A
3: P3 P1 B
It seems like the 2nd 'product' column should never have been there, and its contents are bogus.
Moreover, removing foo from DT1 changes it:
> DT1 <- data.table(product = c("P1","P2","P3"))
> DT2 <- data.table(product = c("P1","P2","P3"), family = c("A","A","B"))
> DT1[DT2,.(product, family), on = "product", by = .EACHI]
product product family
1: P1 P1 A
2: P2 P2 A
3: P3 P3 B
# Output of sessionInfo()
R version 3.4.0 (--)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /opt/R-3.4.0.mkl/lib64/R/lib/libR.so
LAPACK: /opt/R-3.4.0.mkl/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] yaml_2.2.0 R.utils_2.5.0 R.oo_1.21.0 R.methodsS3_1.7.1 xts_0.9-7 zoo_1.8-0 bit64_4.0.5 bit_4.0.4 data.table_1.14.1
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0 grid_3.4.0 lattice_0.20-35
gives:
It seems like the 2nd 'product' column should never have been there, and its contents are bogus.
Moreover, removing
foofrom DT1 changes it:#Output of sessionInfo()R version 3.4.0 (--)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
Matrix products: default
BLAS: /opt/R-3.4.0.mkl/lib64/R/lib/libR.so
LAPACK: /opt/R-3.4.0.mkl/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] yaml_2.2.0 R.utils_2.5.0 R.oo_1.21.0 R.methodsS3_1.7.1 xts_0.9-7 zoo_1.8-0 bit64_4.0.5 bit_4.0.4 data.table_1.14.1
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0 grid_3.4.0 lattice_0.20-35