data(AllstarFull)
# find number of appearances by players in the All Star games
player_appearances <- with(AllstarFull, rev(sort(table(playerID))))
# How many All-Star players, in total?
length(player_appearances)
# density plot of the whole distribution
plot(density(player_appearances), main="Player appearances in All Star Games")
rug(jitter(player_appearances))
# who has played in more than 10 ASGs?
player_appearances[player_appearances > 10]
hist(player_appearances[player_appearances > 10])
# Hank Aaron's All-Star record:
subset(AllstarFull, playerID == "aaronha01")
# Years that Stan Musial played in the ASG:
with(AllstarFull, yearID[playerID == "musiast01"])
# Starting positions he played (NA means did not start)
with(AllstarFull, startingPos[playerID == "musiast01"])
# All-Star rosters from the 1966 ASG
subset(AllstarFull, gameID == "NLS196607120")
# All-Stars from the Washington Nationals
subset(AllstarFull, teamID == "WAS")
# Teams with the fewest All-Stars
rare <- names(which(table(AllstarFull$teamID) < 10))
# Records associated with the 'rare' teams:
# (There are a few teamID typos: can you spot them?)
subset(AllstarFull, teamID %in% rare)
Run the code above in your browser using DataLab