Chapter 2. Exercises 3.
Pitchers in the 350 Wins Club
Analyzing Baseball Data with R, Introduction to R, page 57
The following table lists nine pitchers who have won at least 350 career wins.
Player |
W |
L |
SO |
BB |
Pete Alexander |
373 |
208 |
2198 |
951 |
Roger Clemens |
354 |
184 |
4672 |
1580 |
Pud Galvin |
364 |
310 |
1806 |
745 |
Walter Johnson |
417 |
279 |
3509 |
1363 |
Greg Maddux |
355 |
227 |
3371 |
999 |
Christy Mathewson |
373 |
188 |
2502 |
844 |
Kid Nichols |
361 |
208 |
1868 |
1268 |
Warren Spahn |
363 |
245 |
2583 |
1434 |
Cy Young |
511 |
316 |
2803 |
1217 |
(a) In R, place the wins and losses in the vectors W and L, respectively. Also, create a character vector Name containing the last names of these pitchers.
W <- c(373, 354, 364, 417, 355, 373, 361, 363, 511)
L <- c(208, 184, 310, 279, 227, 188, 208, 245, 316)
Name <- c("Alexander", "Clemens", "Galvin", "Johnson", "Maddux", "Mathewson", "Nichols", "Spahn", "Young")
(b) Compute the winning percentage for all pitchers defined by 100 × W / (W+L) and put these winning percentages in the vector Win.PCT.
Win.PCT <- 100 * W / (W+L)
> Win.PCT
[1] 64.19966 65.79926 54.00593 59.91379 60.99656 66.48841 63.44464 59.70395 61.78960
(c) By use of the command
Wins.350 <- data.frame(Name, W, L, Win.PCT)
create a data frame Wins.350 containing the names, wins, losses, and winning percentages.
(d) By use of the order function, sort the data frame Wins.350 by winning percentage. Among these pitchers, who had the largest and smallest winning percentages?
Young had the largest winning percentages.
Clemens had the smallest winning percentages.
Chap2 Ex3 Pitchers in the 350 Wins Club
'컴퓨터 언어 > R' 카테고리의 다른 글
[R] Chap2 Ex5 Pitcher Strikeout / Walk Ratios (0) | 2015.02.04 |
---|---|
[R] Chap2 Ex4 subset function strikeout-walk ratios (0) | 2015.02.01 |
[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 |