0
對於以下樣本數據集功能之間:錯誤位置必須是0,且n在該過濾器和求和由日期範圍
set.seed(123)
library(dplyr)
Sessions <- ceiling(rnorm(50, mean = 3000, sd = 300))
Registrations <- ceiling(rnorm(50, mean = 800, sd = 100))
Conversions <- ceiling(rnorm(50, mean = 400, sd = 50))
Date_Range = seq(Sys.Date() - 50, Sys.Date() - 1, by = 1)
sample_data <- data.frame(Date_Range,Sessions, Registrations, Conversions)
sample_data <- tbl_df(sample_data)
我已經對於給定的度量,其是爲了提供總和的以下函數日期範圍:
sumByDates <- function(startDate, endDate, metric) {
sum(filter(sample_data, Date_Range >= startDate & Date_Range <= endDate) %>% select(metric))
}
現在,如果我這樣做:
sumByDates(Sys.Date()-5, Sys.Date()-1, Sessions)
我會得到:
Error: Position must be between 0 and n
Called from: combine_vars(vars, ind_list)
Browse[1]> Q
如何在給定Date_Range
的sample_data
中給定指標的總和?