Here is an example of what I am trying to do:
testdf <- data.frame("date" = c("01/01/2019", "01/02/2019", "01/03/2019", "01/05/2019"), "activity" = c("Practice", "Practice", "Game", "Practice"))
testdf$date <- as.Date(testdf$date, "%m/%d/%Y")
testdf$activity <- as.character(testdf$activity)
dateSeq <- function(df, colDate, colActivity){
df$coding <- NULL
gameDates <- pull(df, colDate)
gameDates <- sort(gameDates)
n <- 1
for (i in 1:nrow(df)) {
minGameDate <- gameDates[n]
currentDate <- df$colDate[i]
if (currentDate < minGameDate) {
df$coding[i] <- paste0("G", as.numeric(minGameDate - currentDate))
}
else {
df$coding[i] <- "G"
n <- n + 1
}
}
return(df)
}
Which gives me this error:
Error: var must evaluate to a single number or a column name, not a function
Call rlang::last_error() to see a backtrace