Skip to content

Instantly share code, notes, and snippets.

@batpigandme
Last active October 29, 2018 13:37
Show Gist options
  • Save batpigandme/daff0d8259f4086239ccf09da16ea5fd to your computer and use it in GitHub Desktop.
Save batpigandme/daff0d8259f4086239ccf09da16ea5fd to your computer and use it in GitHub Desktop.
Using {datapasta} with {reprex} for sampled group data frames with dplyr::sample_n()
library(tidyverse)
# add data from gist script
# https://gist.github.com/batpigandme/daff0d8259f4086239ccf09da16ea5fd#file-yest_player_gls-r
# download csv from gist
# https://gist.github.com/batpigandme/daff0d8259f4086239ccf09da16ea5fd#file-yest_player_gls-csv
# or
# read in data from gist as csv
url <- "https://gist.githubusercontent.com/batpigandme/daff0d8259f4086239ccf09da16ea5fd/raw/df7d36be144e48af544e982eb22a7d0a1fe7534f/yest_player_gls.csv"
yest_player_gls <- readr::read_csv(url)
glimpse(yest_player_gls)
# group full dataset by team
by_team <- yest_player_gls %>%
group_by(team)
# user dplyr::sample_n() on grouped data frame
# in this case, we'll take three from each team
sample_gls <- dplyr::sample_n(by_team, 3)
# use output to re-create sample_gls for reprex
datapasta::dpasta(sample_gls)
name team mins pts rbs ast stl blk
Austin Rivers WAS 22 9 1 3 1 1
Otto Porter Jr. WAS 30 6 5 2 2 0
Avery Bradley LAC 23 15 1 5 0 1
Tobias Harris LAC 30 22 11 0 0 0
Montrezl Harrell LAC 16 13 6 1 0 2
Boban Marjanovic LAC 12 13 9 1 1 2
Tyrone Wallace LAC 7 2 0 1 0 0
Jerome Robinson LAC 7 4 0 0 0 0
Mike Scott LAC 19 11 3 2 0 0
Lou Williams LAC 16 17 0 6 1 0
Milos Teodosic LAC 11 3 0 3 1 0
Shai Gilgeous-Alexander LAC 28 10 8 7 2 0
Kelly Oubre Jr. WAS 26 9 4 1 0 0
Tomas Satoransky WAS 16 9 1 3 0 0
Troy Brown Jr. WAS 7 3 4 0 0 0
Thomas Bryant WAS 11 7 3 1 0 0
Jordan McRae WAS 8 0 1 1 0 1
Bradley Beal WAS 29 20 7 0 0 1
Markieff Morris WAS 14 0 1 0 0 0
John Wall WAS 28 18 3 5 4 0
Jeff Green WAS 21 12 8 2 0 0
Ian Mahinmi WAS 29 11 7 0 0 0
Patrick Beverley LAC 25 11 4 4 0 0
Danilo Gallinari LAC 26 11 7 2 2 1
Marcin Gortat LAC 20 4 8 3 0 3
Dorian Finney-Smith DAL 11 3 0 0 0 0
Jalen Brunson DAL 12 2 0 1 0 0
Maxi Kleber DAL 13 11 3 0 0 0
Dwight Powell DAL 11 4 2 0 1 0
J.J. Barea DAL 14 2 2 4 0 0
Luka Doncic DAL 37 14 6 5 1 0
Dennis Smith Jr. DAL 34 27 1 3 0 2
Harrison Barnes DAL 34 7 3 1 3 0
Wesley Matthews DAL 36 22 7 1 1 0
DeAndre Jordan DAL 37 12 19 9 0 1
Ricky Rubio UTA 32 6 1 8 1 0
Jae Crowder UTA 35 15 6 1 1 0
Rudy Gobert UTA 33 23 16 2 2 3
Joe Ingles UTA 31 12 7 5 1 0
Donovan Mitchell UTA 35 20 1 4 1 1
Ekpe Udoh UTA 15 2 2 2 0 1
Dante Exum UTA 16 6 4 3 1 1
Royce O'Neale UTA 17 5 4 0 1 0
Georges Niang UTA 13 13 1 0 0 0
Grayson Allen UTA 13 11 1 0 0 0
Deonte Burton OKC 5 0 0 0 0 0
Terrance Ferguson OKC 27 6 2 0 2 0
Alex Abrines OKC 24 2 1 0 2 0
Nerlens Noel OKC 26 20 15 2 4 1
Jerami Grant OKC 37 14 4 1 1 0
Dennis Schroder OKC 27 12 4 7 0 0
Tyson Chandler PHX 12 4 2 2 0 1
Troy Daniels PHX 17 8 1 1 2 0
Deandre Ayton PHX 32 16 11 3 1 0
Mikal Bridges PHX 22 9 1 0 2 0
Josh Jackson PHX 21 8 1 0 1 1
Richaun Holmes PHX 4 2 2 2 0 0
Isaiah Canaan PHX 6 0 1 2 1 0
Ryan Anderson PHX 31 15 5 0 1 0
Trevor Ariza PHX 28 5 5 3 2 0
T.J. Warren PHX 22 18 8 0 0 1
Jamal Crawford PHX 16 7 2 1 0 0
Elie Okobo PHX 31 18 5 7 0 0
Abdel Nader OKC 2 0 0 0 0 0
Timothe Luwawu-Cabarrot OKC 1 0 0 0 0 0
Patrick Patterson OKC 30 17 4 0 0 0
Paul George OKC 30 23 4 5 3 2
Russell Westbrook OKC 31 23 9 7 4 0
Allen Crabbe BKN 28 14 5 2 0 0
Joe Harris BKN 30 7 3 3 0 0
Jarrett Allen BKN 29 11 3 4 1 2
Caris LeVert BKN 30 23 3 7 0 0
D'Angelo Russell BKN 30 25 6 6 0 1
Rondae Hollis-Jefferson BKN 17 7 2 0 1 0
Stephen Curry GSW 36 35 7 3 1 0
Kevon Looney GSW 12 4 3 0 0 0
Damian Jones GSW 12 2 1 1 1 2
Alfonzo McKinnie GSW 17 9 5 0 1 1
Jordan Bell GSW 10 2 3 1 0 1
Jacob Evans GSW 6 0 0 0 0 0
Andre Iguodala GSW 20 4 5 2 1 1
Kevin Durant GSW 39 34 8 6 1 1
Jonas Jerebko GSW 15 4 6 2 0 0
Klay Thompson GSW 36 18 5 0 1 1
Draymond Green GSW 36 8 4 13 5 0
Jared Dudley BKN 22 6 6 2 3 0
Ed Davis BKN 17 4 7 1 0 0
Shabazz Napier BKN 14 5 1 3 0 0
Spencer Dinwiddie BKN 24 12 1 0 0 0
yest_player_gls <- tibble::tribble(
~name, ~team, ~mins, ~pts, ~rbs, ~ast, ~stl, ~blk,
"Austin Rivers", "WAS", 22, 9, 1, 3, 1, 1,
"Otto Porter Jr.", "WAS", 30, 6, 5, 2, 2, 0,
"Avery Bradley", "LAC", 23, 15, 1, 5, 0, 1,
"Tobias Harris", "LAC", 30, 22, 11, 0, 0, 0,
"Montrezl Harrell", "LAC", 16, 13, 6, 1, 0, 2,
"Boban Marjanovic", "LAC", 12, 13, 9, 1, 1, 2,
"Tyrone Wallace", "LAC", 7, 2, 0, 1, 0, 0,
"Jerome Robinson", "LAC", 7, 4, 0, 0, 0, 0,
"Mike Scott", "LAC", 19, 11, 3, 2, 0, 0,
"Lou Williams", "LAC", 16, 17, 0, 6, 1, 0,
"Milos Teodosic", "LAC", 11, 3, 0, 3, 1, 0,
"Shai Gilgeous-Alexander", "LAC", 28, 10, 8, 7, 2, 0,
"Kelly Oubre Jr.", "WAS", 26, 9, 4, 1, 0, 0,
"Tomas Satoransky", "WAS", 16, 9, 1, 3, 0, 0,
"Troy Brown Jr.", "WAS", 7, 3, 4, 0, 0, 0,
"Thomas Bryant", "WAS", 11, 7, 3, 1, 0, 0,
"Jordan McRae", "WAS", 8, 0, 1, 1, 0, 1,
"Bradley Beal", "WAS", 29, 20, 7, 0, 0, 1,
"Markieff Morris", "WAS", 14, 0, 1, 0, 0, 0,
"John Wall", "WAS", 28, 18, 3, 5, 4, 0,
"Jeff Green", "WAS", 21, 12, 8, 2, 0, 0,
"Ian Mahinmi", "WAS", 29, 11, 7, 0, 0, 0,
"Patrick Beverley", "LAC", 25, 11, 4, 4, 0, 0,
"Danilo Gallinari", "LAC", 26, 11, 7, 2, 2, 1,
"Marcin Gortat", "LAC", 20, 4, 8, 3, 0, 3,
"Dorian Finney-Smith", "DAL", 11, 3, 0, 0, 0, 0,
"Jalen Brunson", "DAL", 12, 2, 0, 1, 0, 0,
"Maxi Kleber", "DAL", 13, 11, 3, 0, 0, 0,
"Dwight Powell", "DAL", 11, 4, 2, 0, 1, 0,
"J.J. Barea", "DAL", 14, 2, 2, 4, 0, 0,
"Luka Doncic", "DAL", 37, 14, 6, 5, 1, 0,
"Dennis Smith Jr.", "DAL", 34, 27, 1, 3, 0, 2,
"Harrison Barnes", "DAL", 34, 7, 3, 1, 3, 0,
"Wesley Matthews", "DAL", 36, 22, 7, 1, 1, 0,
"DeAndre Jordan", "DAL", 37, 12, 19, 9, 0, 1,
"Ricky Rubio", "UTA", 32, 6, 1, 8, 1, 0,
"Jae Crowder", "UTA", 35, 15, 6, 1, 1, 0,
"Rudy Gobert", "UTA", 33, 23, 16, 2, 2, 3,
"Joe Ingles", "UTA", 31, 12, 7, 5, 1, 0,
"Donovan Mitchell", "UTA", 35, 20, 1, 4, 1, 1,
"Ekpe Udoh", "UTA", 15, 2, 2, 2, 0, 1,
"Dante Exum", "UTA", 16, 6, 4, 3, 1, 1,
"Royce O'Neale", "UTA", 17, 5, 4, 0, 1, 0,
"Georges Niang", "UTA", 13, 13, 1, 0, 0, 0,
"Grayson Allen", "UTA", 13, 11, 1, 0, 0, 0,
"Deonte Burton", "OKC", 5, 0, 0, 0, 0, 0,
"Terrance Ferguson", "OKC", 27, 6, 2, 0, 2, 0,
"Alex Abrines", "OKC", 24, 2, 1, 0, 2, 0,
"Nerlens Noel", "OKC", 26, 20, 15, 2, 4, 1,
"Jerami Grant", "OKC", 37, 14, 4, 1, 1, 0,
"Dennis Schroder", "OKC", 27, 12, 4, 7, 0, 0,
"Tyson Chandler", "PHX", 12, 4, 2, 2, 0, 1,
"Troy Daniels", "PHX", 17, 8, 1, 1, 2, 0,
"Deandre Ayton", "PHX", 32, 16, 11, 3, 1, 0,
"Mikal Bridges", "PHX", 22, 9, 1, 0, 2, 0,
"Josh Jackson", "PHX", 21, 8, 1, 0, 1, 1,
"Richaun Holmes", "PHX", 4, 2, 2, 2, 0, 0,
"Isaiah Canaan", "PHX", 6, 0, 1, 2, 1, 0,
"Ryan Anderson", "PHX", 31, 15, 5, 0, 1, 0,
"Trevor Ariza", "PHX", 28, 5, 5, 3, 2, 0,
"T.J. Warren", "PHX", 22, 18, 8, 0, 0, 1,
"Jamal Crawford", "PHX", 16, 7, 2, 1, 0, 0,
"Elie Okobo", "PHX", 31, 18, 5, 7, 0, 0,
"Abdel Nader", "OKC", 2, 0, 0, 0, 0, 0,
"Timothe Luwawu-Cabarrot", "OKC", 1, 0, 0, 0, 0, 0,
"Patrick Patterson", "OKC", 30, 17, 4, 0, 0, 0,
"Paul George", "OKC", 30, 23, 4, 5, 3, 2,
"Russell Westbrook", "OKC", 31, 23, 9, 7, 4, 0,
"Allen Crabbe", "BKN", 28, 14, 5, 2, 0, 0,
"Joe Harris", "BKN", 30, 7, 3, 3, 0, 0,
"Jarrett Allen", "BKN", 29, 11, 3, 4, 1, 2,
"Caris LeVert", "BKN", 30, 23, 3, 7, 0, 0,
"D'Angelo Russell", "BKN", 30, 25, 6, 6, 0, 1,
"Rondae Hollis-Jefferson", "BKN", 17, 7, 2, 0, 1, 0,
"Stephen Curry", "GSW", 36, 35, 7, 3, 1, 0,
"Kevon Looney", "GSW", 12, 4, 3, 0, 0, 0,
"Damian Jones", "GSW", 12, 2, 1, 1, 1, 2,
"Alfonzo McKinnie", "GSW", 17, 9, 5, 0, 1, 1,
"Jordan Bell", "GSW", 10, 2, 3, 1, 0, 1,
"Jacob Evans", "GSW", 6, 0, 0, 0, 0, 0,
"Andre Iguodala", "GSW", 20, 4, 5, 2, 1, 1,
"Kevin Durant", "GSW", 39, 34, 8, 6, 1, 1,
"Jonas Jerebko", "GSW", 15, 4, 6, 2, 0, 0,
"Klay Thompson", "GSW", 36, 18, 5, 0, 1, 1,
"Draymond Green", "GSW", 36, 8, 4, 13, 5, 0,
"Jared Dudley", "BKN", 22, 6, 6, 2, 3, 0,
"Ed Davis", "BKN", 17, 4, 7, 1, 0, 0,
"Shabazz Napier", "BKN", 14, 5, 1, 3, 0, 0,
"Spencer Dinwiddie", "BKN", 24, 12, 1, 0, 0, 0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment