[This article was first published on R – What You're Doing Is Rather Desperate, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
When Marlion Pickett runs onto the M.C.G for Richmond in the AFL Grand Final this Saturday, he’ll be only the sixth player in 124 finals to debut on the big day.
The sole purpose of this blog post is to illustrate how incredibly easy it is to figure this out, thanks to the dplyr and fitzRoy packages.
library(dplyr) library(fitzRoy) afldata <- get_afltables_stats() afldata %>% select(Season, Round, Date, ID, First.name, Surname, Playing.for, Home.team, Home.score, Away.team, Away.score) %>% group_by(ID) %>% arrange(Date) %>% # a player's first game slice(1) %>% ungroup() %>% # grand finals only filter(Round == "GF") %>% # get the winning/losing margin mutate(Margin = case_when(Playing.for == Home.team ~ Home.score - Away.score, TRUE ~ Away.score - Home.score)) %>% select(-Home.team, -Away.team, Home.score, Away.score)
Season | Round | Date | ID | First.name | Surname | Playing.for | Margin |
---|---|---|---|---|---|---|---|
1908 | GF | 1908-09-26 | 5573 | Harry | Prout | Essendon | -9 |
1920 | GF | 1920-10-02 | 6677 | Billy | James | Richmond | 17 |
1923 | GF | 1923-10-20 | 6915 | George | Rawle | Essendon | 17 |
1926 | GF | 1926-10-09 | 3824 | Francis | Vine | Melbourne | 57 |
1952 | GF | 1952-09-27 | 9361 | Keith | Batchelor | Collingwood | -46 |
To leave a comment for the author, please follow the link and comment on their blog: R – What You're Doing Is Rather Desperate.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.