Description Usage Arguments Details Value Author(s) See Also Examples
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.
1 2 3 |
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 NA
s 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
1 2 3 4 | bstats <- battingStats()
str(bstats)
bstats <- battingStats(cbind=FALSE)
str(bstats)
|
'data.frame': 102816 obs. of 29 variables:
$ playerID: chr "abercda01" "addybo01" "allisar01" "allisdo01" ...
$ yearID : int 1871 1871 1871 1871 1871 1871 1871 1871 1871 1871 ...
$ stint : int 1 1 1 1 1 1 1 1 1 1 ...
$ teamID : Factor w/ 149 levels "ALT","ANA","ARI",..: 136 111 39 142 111 56 111 24 56 24 ...
$ lgID : Factor w/ 7 levels "AA","AL","FL",..: 4 4 4 4 4 4 4 4 4 4 ...
$ G : int 1 25 29 27 25 12 1 31 1 18 ...
$ AB : int 4 118 137 133 120 49 4 157 5 86 ...
$ R : int 0 30 28 28 29 9 0 66 1 13 ...
$ H : int 0 32 40 44 39 11 1 63 1 13 ...
$ X2B : int 0 6 4 10 11 2 0 10 1 2 ...
$ X3B : int 0 0 5 2 3 1 0 9 0 1 ...
$ HR : int 0 0 0 2 0 0 0 0 0 0 ...
$ RBI : int 0 13 19 27 16 5 2 34 1 11 ...
$ SB : int 0 8 3 1 6 0 0 11 0 1 ...
$ CS : int 0 1 1 1 2 1 0 6 0 0 ...
$ BB : int 0 4 2 0 2 0 1 13 0 0 ...
$ SO : int 0 0 5 2 1 1 0 1 0 0 ...
$ IBB : int NA NA NA NA NA NA NA NA NA NA ...
$ HBP : int NA NA NA NA NA NA NA NA NA NA ...
$ SH : int NA NA NA NA NA NA NA NA NA NA ...
$ SF : int NA NA NA NA NA NA NA NA NA NA ...
$ GIDP : int NA NA NA NA NA NA NA NA NA NA ...
$ BA : num 0 0.271 0.292 0.331 0.325 0.224 0.25 0.401 0.2 0.151 ...
$ PA : num 4 122 139 133 122 49 5 170 5 86 ...
$ TB : num 0 38 54 64 56 15 1 91 2 17 ...
$ SlugPct : num 0 0.322 0.394 0.481 0.467 0.306 0.25 0.58 0.4 0.198 ...
$ OBP : num 0 0.295 0.302 0.331 0.336 0.224 0.4 0.447 0.2 0.151 ...
$ OPS : num 0 0.617 0.696 0.812 0.803 ...
$ BABIP : num 0 0.271 0.303 0.326 0.328 0.229 0.25 0.404 0.2 0.151 ...
'data.frame': 102816 obs. of 12 variables:
$ playerID: chr "abercda01" "addybo01" "allisar01" "allisdo01" ...
$ yearID : int 1871 1871 1871 1871 1871 1871 1871 1871 1871 1871 ...
$ stint : int 1 1 1 1 1 1 1 1 1 1 ...
$ teamID : Factor w/ 149 levels "ALT","ANA","ARI",..: 136 111 39 142 111 56 111 24 56 24 ...
$ lgID : Factor w/ 7 levels "AA","AL","FL",..: 4 4 4 4 4 4 4 4 4 4 ...
$ BA : num 0 0.271 0.292 0.331 0.325 0.224 0.25 0.401 0.2 0.151 ...
$ PA : num 4 122 139 133 122 49 5 170 5 86 ...
$ TB : num 0 38 54 64 56 15 1 91 2 17 ...
$ SlugPct : num 0 0.322 0.394 0.481 0.467 0.306 0.25 0.58 0.4 0.198 ...
$ OBP : num 0 0.295 0.302 0.331 0.336 0.224 0.4 0.447 0.2 0.151 ...
$ OPS : num 0 0.617 0.696 0.812 0.803 ...
$ BABIP : num 0 0.271 0.303 0.326 0.328 0.229 0.25 0.404 0.2 0.151 ...
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.