首页 > 解决方案 > 在与子集数据表连接的情况下,为什么列优先于数据表中同名的对象

问题描述

test <- function() {
  operator_descriptions <- data.table(operator = "/", description = "/")
  operator_conditions <- data.table(operator = "/", condition = "Quotient non zero")
  condition <- c(TRUE)
  operator_conditions[operator_descriptions[condition], on = c("operator")]
}

test()

Output
Error: When i is a data.table (or character vector), the columns to join by must be specified either using 'on=' argument (see ?data.table) or by keying x (i.e. sorted, and, marked as sorted, see ?setkey). Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.

尽管 condition 在 的范围内operator_descriptions,但conditioncolumn ofoperator_conditions似乎优先condition于前面语句中定义的对象。

这种行为需要对名称等保持谨慎。虽然在正常情况下,这很好,因为我们打算主要使用列名。但在这样的情况下,我不确定这是否是故意的。

标签: rdata.table

解决方案


推荐阅读