Chapter 2. Exercises 4.
subset function strikeout-walk ratios
Analyzing Baseball Data with R, Introduction to R, page 58
(a) In R, place the strikeout and walk totals from the 350 win pitchers in the vectors SO and BB, respectively. Also, create a character vector Name containing the last names of these pitchers.
SO <- c(2198, 4672, 1806, 3509, 3371, 2502, 1868, 2583, 2803)
BB <- c(951, 1580, 745, 1363, 999, 844, 1268, 1434, 1217)
Name <- c("Alexander", "Clemens", "Galvin", "Johnson", "Maddux", "Mathewson", "Nichols", "Spahn", "Young")
d2a34c366639589107a79f26f3ec2ba5
(b) Compute the strikeout-walk ratio by SO / BB and put these ratios in the vector SO.BB.Ratio.
SO.BB.Ratio <- SO / BB
> SO.BB.Ratio
[1] 2.311251 2.956962 2.424161 2.574468 3.374374 2.964455 1.473186 1.801255 2.303205
(c) By use of the command
SO.BB <- data.frame(Name, SO, BB, SO.BB.Ratio)
create a data frame SO.BB containing the names, strikeouts, walks, and strikeout-walk ratios.
(d) By use of the subset function, find the pitchers who had a strikeout-walk ratio exceeding 2.8.
subset(SO.BB, SO.BB.Ratio > 2.8)
Clemens, Maddux and Mathewson had a strikeout-walk ratio exceeding 2.8.
(e) By use of the order function, sort the data frame by the number of walks. Did the pitcher with the largest number of walks have a high or low strikeout-walk ratio?
No, the pitcher with the largest number of walks didn't have a high or low strikeout-walk ratio.
SO.BB <- SO.BB [order(SO.BB$BB, decreasing=TRUE), ]
Chap2 Ex4 subset function strikeout-walk ratios
'컴퓨터 언어 > R' 카테고리의 다른 글
[R] Chap2 Ex5 Pitcher Strikeout / Walk Ratios (0) | 2015.02.04 |
---|---|
[R] Chap2 Ex3 Pitchers in the 350 Wins Club (0) | 2015.01.31 |
[R] Chap2 Ex2 Character, Factor, and Logical Variables in R (0) | 2015.01.30 |
[R] Chap2 Ex1 Top Base Stealers in the Hall of Frame (0) | 2015.01.29 |
R 통계 프로그램 사용법 및 설치 매뉴얼 다운로드 소개 (11) | 2015.01.27 |