I have the following data
Name <- c("Kobe Bryant", "Kobe Bryant", "Kobe Bryant",
"Kobe Bryant", "Kobe Bryant", "Kobe Bryant",
"Lebron James", "Lebron James", "Lebron James",
"Lebron James", "Kevin Durant", "Kevin Durant",
"Kevin Durant", "Kevin Durant", "Kevin Durant")
Date <- as.Date(c("2015-05-14", "2015-05-15", "2015-05-19", "2015-05-21",
"2015-05-24", "2015-05-28", "2015-05-14", "2015-05-20",
"2015-05-21", "2015-05-23", "2015-05-22", "2015-05-24",
"2015-05-28", "2015-06-02", ""2015-06-04"))
df <- data.frame c(Name, Date)
Desired_output <- c(1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0)
df2 <- data.frame c(Name, Date, Desired_output)
I want to create a new column that identifies the back-to-back games (playing a game two consecutive days) for a specific player.
Output of the column: 1 (if b2b) 0 if not.
Both the first day and the second day of the b2b should have a 1.