GameID Drive down yrdln PlayType sp
2009091000 1 1 22 run 0
2009091000 1 2 25 pass 0
2009091000 1 3 32 sack 0
2009091000 2 1 42 pass 0
2009091000 2 2 44 run 0
2009091000 2 3 43 pass 0
2009091000 2 4 33 Field Goal 1
2009091001 1 1 5 pass 0
2009091001 1 2 10 pass 1
The above data is similar to a data frame I am currently working with. I am attempting to determine the "yrdln" for the first entry for each "drive" and the "yrdln" for the last entry for each "drive". But each GameID has many drive 1, drive 2, and so on.
I have been trying to Group_by GameID, then Drive, and then somehow determine the first and last entry for each, but I am having trouble doing this. I also still want the sp and PlayType included for these entries, or at least included for the "last" entry as I want to know the outcome of the drive (if there was a scoring play and what type of play it was)
dput:
df <- structure(list(GameID = c(2009091000, 2009091000, 2009091000,
2009091000, 2009091000, 2009091000, 2009091000, 2009091001, 2009091001
), Drive = c(1, 1, 1, 2, 2, 2, 2, 1, 1), down = c(1, 2, 3, 1,
2, 3, 4, 1, 2), yrdln = c(22, 25, 32, 42, 44, 43, 33, 5, 10),
PlayType = c("run", "pass", "sack", "pass", "run", "pass",
"Field Goal", "pass", "pass"), sp = c(0, 0, 0, 0, 0, 0, 1,
0, 1)), row.names = c(NA, -9L), class = c("tbl_df", "tbl",
"data.frame"))