我正在尝试使用 bigrquery 和 dbplyr 来获取日期对应的一年中的一周(即与 相同lubridate::week()
,即
library(lubridate)
library(dbplyr)
library(bigrquery)
week("2015-08-11")
# [1] 32
但我正在使用bigrquery
和dbplyr
到目前为止我尝试过的
使用lubridate::week()
我看到
transactions %>%
select(item, date) %>%
mutate(week = week(date)) %>%
collect()
Error: Function not found: week at [1:30] [invalidQuery]
所以我尝试了这个自制的解决方案
transactions %>%
select(item, date) %>%
mutate(week = strftime(date, format = "%V")) %>%
collect()
Error: Syntax error: Expected ")" but got keyword AS at [1:54] [invalidQuery]
In addition: Warning message:
Named arguments ignored for SQL strftime
以及另一个(相当丑陋的)自制解决方案
transactions %>%
select(item, date) %>%
mutate(week = as.numeric((as.Date(date) - as.Date(paste0(substr(date, 1, 4), "-01-01"))), units="days") %/% 7) %>%
collect()
Error in as.numeric((as.Date(date) - as.Date(paste0(substr(date, 1, :
unused argument (units = "days")
但我似乎找不到使用 bigquery 和 dbplyr 获取周数的方法