Re: [R] If Loop With Lagged Variable

2019-09-19 Thread Rui Barradas
Hello, The following might be a better solution. I include a minimal data set as an example. Date <- c(rep(as.Date("2018-03-29"), 4), rep(as.Date("2018-03-30"), 4), rep(as.Date("2018-04-01"), 4)) ari18.test3 <- data.frame(Date) ari18.test3$GameNum <- 1 #--- d <- c(0, diff

Re: [R] If Loop With Lagged Variable

2019-09-19 Thread Rui Barradas
Hello, There was no attachment, R-Help allows only a limited number of file types, see the posting guide and try reposting. As for the question, try ifelse, the vectorized fom of if/else. ifelse(ari18.test3$Date > lag(ari18.test3$Date), ari18.tesm3$GameNum + 1, ari18.test3$gameNum) (Not t

[R] If Loop With Lagged Variable

2019-09-19 Thread Phillip Heinrich
Attached is every at bat for the Arizona Diamondback’s first three games of 2018 – BBdata1.rda. I added the Date and DHCode variables by parsing the first variable labeled GameID. BBdata2 is a reduced dataset with five variables as shown in the str() command. data.frame':234 obs. of 5 var