问题描述
我在运行非对等连接(来自 R 的 data.table 库)时发现了一个奇怪的行为,我不知道为什么会发生这种情况。
为什么在运行非对等连接时,如果我想保留左表的原始值,我需要在{{}里面写 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
而不是只写x.colname
1}} 连接的属性?
这是我所说的一个可重现的小例子:
colname
这是 j
的快照(在 library(tidyverse)
library(data.table)
# Setting seed for reproducibility
set.seed(666)
# data.table that contains roadway segments.
# The "frm_dfo" and "to_dfo" columns represent the start and end mileposts
# of each roadway segment. For example,the segment with road_ID=101 refers
# to the portion of IH20 that starts at milepost 10 and ends at milepost 20.
roads = data.table(road_id=101:109,hwy=c('IH20','IH20','SH150','TX66','TX66'),frm_dfo=c(10,20,30,10,30),to_dfo=c(20,40,40),seg_name=c('Seg 1','Seg 2','Seg 3','Seg 10','Seg 20','Seg 30','Seg 100','Seg 200','Seg 300'))
# data.table that contains crashes.
# The "dfo" column represents the milepost of the roadway on which the
# crash occurs. For example,the crash with crash_id=1 happens on milepost 33.23105 of IH20.
crashes = data.table(crash_id=1:30,hwy=rep(c('IH20','BOB11'),each=10),dfo=runif(min=10,max=40,n=30))
# Non-equi join that finds which segment each crash happens on.
joined_data_v1 = crashes %>%
.[roads,j = list(crash_id,hwy,x.dfo,seg_name,frm_dfo,to_dfo),on = list(hwy=hwy,dfo >= frm_dfo,dfo <= to_dfo)] %>%
arrange(crash_id,by_group = TRUE)
# Again,joining crashes and roadway segments.
# Here,though,note that I've swapped x.dfo for just dfo inside the `j` argument
joined_data_v2 = crashes %>%
.[roads,dfo,by_group = TRUE)
参数中使用 joined_data_v1
):
这是 x.dfo
的快照(在 j
参数中使用 joined_data_v2
):
请注意,在 dfo
中,名为 j
的列如何包含 joined_data_v1
数据表中 x.dfo
列的确切值。但是,在 dfo
中,名为 crashes
的列包含来自 joined_data_v2
data.table 的 dfo
列的值(而不是来自 {{1} } data.table 的 frm_dfo
列)。
这里发生了什么?为什么这行为如此奇怪?为什么结果 data.table 的 roads
列中包含的值并不总是准确反映 crashes
data.table 中原始 dfo
列中包含的内容?
我尝试查看非 equi 连接的一些文档,但在这里找不到任何可以帮助我的内容。
Here 是一个相关的问题,但他们没有提到为什么会发生这种行为。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)