我正在尝试将前同事的脚本从sqldf
重写为tidyverse
。我不能遵循这一块。两个名为“ data”和“ Stt_nm”的数据帧被合并,但是我不明白为什么他使用了两个选择。也许我在这里错过了一些东西。
output = sqldf(
paste0(
"select a.date,b.name,sum(a.weigh) as rch
from (select distinct date,ID,IndID,Station_id,weigh from data) as a
left join Stt_nm as b on a.Station_id=b.Station
where a.date between ",
startdate,
" and ",
enddate,
"
group by a.date,b.name"
)
)
答案 0 :(得分:1)
如果没有可复制的示例,我无法确定,但是我认为应该这样做:
library(tidyverse)
data %>%
select(date, ID, IndID, Station_id, weigh) %>%
left_join(Stt_nm, by="Station") %>%
filter(date <= startdate & date >= enddate) %>%
group_by(date, name) %>%
summarize(rch = sum(weigh))