Skip to content

i, := and Cartesian product (another allow.cartesian case) #800

@matthieugomez

Description

@matthieugomez
DT=data.table(
  id = c(1, 1),
  date = c(1992, 1991),
  value = c(4.1, 4.5),
  key = "id"
)

DT[DT, a := 1]
"Error in vecseq(f__, len__, if (allow.cartesian || notjoin) NULL else as.integer(max(nrow(x),  : 
  Join results in 4 rows; more than 2 = max(nrow(x),nrow(i)). Check for duplicate key values in i, each of which join to the same group in x over and over again. If that's ok, try including `j` and dropping `by` (by-without-by) so that j runs for each group to avoid the large allocation. If you are sure you wish to proceed, rerun with allow.cartesian=TRUE. Otherwise, please search for this error message in the FAQ, Wiki, Stack Overflow and datatable-help for advice."
DT[DT, a := 1, allow.cartesian = TRUE]

does not throw any error even though it does not do a cartesian product.

Update: Also, I'm not clear on what happens when multiple rows in i corresponds to a row in X, as in

DT1 <- unique(DT)
DT1[DT, a := i.value]

It seems to match to the last row in i in this example. Is it documented somewhere?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions