R Example – NHL 2017 1st Round Playoff Games

Introduction

I’m usually interested in the NHL game stats, but rarely pay enough attention to the broadcast when stats are announced.  For example, the hockey team’s record when that team scores the first goal of the game.  Or what is the number of blocked shots for a team.  I captured some game data during the first round of the NHL 2017 Playoffs.

Example Files

  1. Go to the following github repository

https://github.com/mndatascienceexamples/datascienceexamples

  1. Go into R-nhl_2017_playoffs directory
  2. Download all files into working directory -> C:\R

RStudio Setup

First, change RStudio’s working directory to c:\R directory

setwd(“C:\\R”)

After RStudio’s working directory is set, then run the R script to set up environment.

source(“nhlGamesREnvSetup.R”)

nhlGamesREnvSetup.R script is a quick way to load nhl 2017 playoff game data and all scripts associated with different statistics.  You could load the game data, then just load an individual script.

NHL 2017 Playoff Statistics

R function calls that are available

## nhlOppScoreFirst.R
allTeamsOppScoreFirstRecords(games)

## nhlTeamsBlockedShots.R
allTeamsBlockedShots(games)

## nhlTeamsFaceoffs.R
allTeamsFO(games)

## nhlTeamsHits.R
allTeamsHits(games)

## nhlTeamsMatchup.R
playoffMatchup(games, “MIN”, “STL”)

## nhlTeamsPenaltyKill.R
allTeamsPK(games)

## nhlTeamsPowerPlay.R
allTeamsPP(games)

## nhlTeamsScoreFirst.R
allTeamsScoreFirstRecords(games)

## nhlTeamsScoring.R
allTeamsScoring(games)

## nhlTeamsShotsOnGoal.R
allTeamsSOG(games)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: