Skip to content

Instantly share code, notes, and snippets.

@juanitobanca
Last active March 11, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanitobanca/275ce4cdab0c612e73914cfca3fe9cc2 to your computer and use it in GitHub Desktop.
Save juanitobanca/275ce4cdab0c612e73914cfca3fe9cc2 to your computer and use it in GitHub Desktop.
f_park_factors <- function( p_year, p_data, p_hist )
{
p_data %>%
filter( YEAR <= p_year & YEAR >= p_year - p_hist + 1 ) %>%
group_by( TEAM_ID, PARK_ID ) %>%
summarise( H_RS = sum( x = H_RS )
, H_RA = sum( x = H_RA )
, H_G = sum( x = H_G )
, A_RS = sum( x = A_RS )
, A_RA = sum( x = A_RA )
, A_G = sum( x = A_G )
, YEARS = n()
) %>%
mutate( YEAR = p_year
, PK_FACTOR = ((H_RS + H_RA)/H_G)/((A_RS + A_RA)/A_G)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment