| battingStats {Lahman} | R Documentation | 
The Batting does not contain batting statistics derived from those
present in the data.frame.  This function calculates
batting average (BA),
plate appearances (PA),
total bases (TB),
slugging percentage (SlugPct),
on-base percentage (OBP),
on-base percentage + slugging (OPS), and
batting average on balls in play (BABIP)
for each record in a Batting-like data.frame.
battingStats(data = Batting, idvars = c("playerID", "yearID", "stint", "teamID", "lgID"), 
             cbind = TRUE)
data | 
 input data, typically   | 
idvars | 
 ID variables to include in the output data.frame  | 
cbind | 
 If   | 
Standard calculations, e.g., BA <- H/AB are problematic because of the
presence of NAs and zeros.  This function tries to deal with those
problems.
A data.frame with all the observations in data.
If cbind==FALSE, only the idvars and the calculated variables are returned.
Michael Friendly, Dennis Murphy
    bstats <- battingStats()
    str(bstats)
## 'data.frame':    96600 obs. of  31 variables:
##  $ playerID : chr  "aardsda01" "aardsda01" "aardsda01" "aardsda01" ...
##  $ yearID   : int  2004 2006 2007 2008 2009 2010 2012 1954 1955 1956 ...
##  $ stint    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ teamID   : Factor w/ 149 levels "ALT","ANA","ARI",..: 117 35 33 16 116 116 93 80 80 80 ...
##  $ lgID     : Factor w/ 7 levels "AA","AL","FL",..: 5 5 2 2 2 2 2 5 5 5 ...
##  $ G        : int  11 45 25 47 73 53 1 122 153 153 ...
##  $ G_batting: int  11 43 2 5 3 4 NA 122 153 153 ...
##  $ AB       : int  0 2 0 1 0 0 NA 468 602 609 ...
##  $ R        : int  0 0 0 0 0 0 NA 58 105 106 ...
##  $ H        : int  0 0 0 0 0 0 NA 131 189 200 ...
##  $ X2B      : int  0 0 0 0 0 0 NA 27 37 34 ...
##  $ X3B      : int  0 0 0 0 0 0 NA 6 9 14 ...
##  $ HR       : int  0 0 0 0 0 0 NA 13 27 26 ...
##  $ RBI      : int  0 0 0 0 0 0 NA 69 106 92 ...
##  $ SB       : int  0 0 0 0 0 0 NA 2 3 2 ...
##  $ CS       : int  0 0 0 0 0 0 NA 2 1 4 ...
##  $ BB       : int  0 0 0 0 0 0 NA 28 49 37 ...
##  $ SO       : int  0 0 0 1 0 0 NA 39 61 54 ...
##  $ IBB      : int  0 0 0 0 0 0 NA NA 5 6 ...
##  $ HBP      : int  0 0 0 0 0 0 NA 3 3 2 ...
##  $ SH       : int  0 1 0 0 0 0 NA 6 7 5 ...
##  $ SF       : int  0 0 0 0 0 0 NA 4 4 7 ...
##  $ GIDP     : int  0 0 0 0 0 0 NA 13 20 21 ...
##  $ G_old    : int  11 45 2 5 NA NA NA 122 153 153 ...
##  $ BA       : num  NA 0 NA 0 NA NA NA 0.28 0.314 0.328 ...
##  $ PA       : num  0 3 0 1 0 0 0 509 665 660 ...
##  $ TB       : num  0 0 0 0 0 0 0 209 325 340 ...
##  $ SlugPct  : num  NA 0 NA 0 NA NA NA 0.447 0.54 0.558 ...
##  $ OBP      : num  NA 0 NA 0 NA NA NA 0.322 0.366 0.365 ...
##  $ OPS      : num  NA 0 NA 0 NA NA NA 0.769 0.906 0.923 ...
##  $ BABIP    : num  NA 0 NA NaN NA NA NA 0.281 0.313 0.325 ...
    bstats <- battingStats(cbind=FALSE)
    str(bstats)
## 'data.frame':    96600 obs. of  12 variables:
##  $ playerID: chr  "aardsda01" "aardsda01" "aardsda01" "aardsda01" ...
##  $ yearID  : int  2004 2006 2007 2008 2009 2010 2012 1954 1955 1956 ...
##  $ stint   : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ teamID  : Factor w/ 149 levels "ALT","ANA","ARI",..: 117 35 33 16 116 116 93 80 80 80 ...
##  $ lgID    : Factor w/ 7 levels "AA","AL","FL",..: 5 5 2 2 2 2 2 5 5 5 ...
##  $ BA      : num  NA 0 NA 0 NA NA NA 0.28 0.314 0.328 ...
##  $ PA      : num  0 3 0 1 0 0 0 509 665 660 ...
##  $ TB      : num  0 0 0 0 0 0 0 209 325 340 ...
##  $ SlugPct : num  NA 0 NA 0 NA NA NA 0.447 0.54 0.558 ...
##  $ OBP     : num  NA 0 NA 0 NA NA NA 0.322 0.366 0.365 ...
##  $ OPS     : num  NA 0 NA 0 NA NA NA 0.769 0.906 0.923 ...
##  $ BABIP   : num  NA 0 NA NaN NA NA NA 0.281 0.313 0.325 ...