The mutate function can be used to add a column to a data frame using the familiar R programming syntax you have seen elsewhere. In this case, we are adding a column to the data frame that has the percentage of time the player got a hit when at bat:
pct <- mutate(players, hitpct = h / ab) head(pct)
You can see the new column on the right in the preceding display. If we run a summary, we will get a summary of all fields (including the new hitpct):
summary(pct)
With the max at 1.0, that would mean some players got a hit every time they were at bat. Similarly, those with 0.0 never got a hit. It looks like a narrow range in the 20% area. Assume the 1.0 is one at bat and one hit, as all the other values are measured in multiple decimal points.