mlb_teams | R Documentation |
A subset of data on Major League Baseball teams from Lahman's Baseball Database. The full dataset is available in the Lahman R package.
mlb_teams
A data frame with 2784 rows and 41 variables.
Year of play.
League the team plays in with levels AL (American League) and NL (National League).
Division the team plays in with levels W (west), E (east) and C (central).
Team's rank in their division at the end of the regular season.
Games played.
Games played at home.
Number of games won.
Number of games lost.
Did the team win their division? Levels of Y (yes) and N (no).
Was the team a wild card winner. Levels of Y (yes) and N (no).
Did the team win their league? Levels of Y (yes) and N (no).
Did the team win the World Series? Levels of Y (yes) and N (no).
Number of runs scored during the season.
Number of at bats during the season.
Number of hits during the season. Includes singles, doubles, triples and homeruns.
Number of doubles hit.
Number of triples hit.
Homeruns by batters.
Number of walks.
Number of batters struckout.
Number of stolen bases.
Number of base runners caught stealing.
Number of batters hit by a pitch.
Number of sacrifice flies.
Number of runs scored by opponents.
Number of earned runs allowed.
Earned run average.
Number of games where a single pitcher played the entire game.
Number of shutouts.
Number of saves.
Number of outs pitched for the season (number of innings pitched times 3).
Number of hits made by opponents.
Number of homeruns hit by opponents.
Number of opponents who were walked.
Number of opponents who were struckout.
Number of errors.
Number of double plays.
Teams fielding percentage.
Full name of team.
Home ballpark name.
Home attendance total.
Lahmans Baseball Database
library(dplyr)
# List the World Series winning teams for each year
mlb_teams |>
filter(world_series_winner == "Y") |>
select(year, team_name, ball_park)
# List the teams with their average number of wins and losses
mlb_teams |>
group_by(team_name) |>
summarize(mean_wins = mean(wins), mean_losses = mean(losses)) |>
arrange((team_name))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.