Problem 1a. 2 4 6; b. 6 10 12; c. 5 Problem 2
- 1 2 3 (result not stored intox). b. 2 4 6 c. 1 2 3 (result not stored intox)
- 2 3 4
Problem 3
1:10
## [1] 1 2 3 4 5 6 7 8 9 10
1:10
## [1] 2 4 6 8 10 12 14 16 18 20
1:102
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## [91] 91 92 93 94 95 96 97 98 99 100
1:10
## [1] 2 3 4 5 6 7 8 9 10 11
1:(10)
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
rep(c(1,1,2),)
## [1] 1 1 2 1 1 2
seq(from =,,)
## [1] 0.0 2.5 5.0 7.5 10.0
Problem 4 p(0,1,0.2) plot(p,p*(1-p),type='l') 1 Data in R { Solutions 1 Solutions Manual for Probability, Statistics, and Data A Fresh Approach Using R, 1e by Darrin Speegle, Bryan Clair (All Chapters) 1 / 4
0.0 0.2 0.4 0.6 0.8 1.0
0.00 0.15 p p * (1 − p) p(0,1,0.01) plot(p,p*(1-p),type='l')0.0 0.2 0.4 0.6 0.8 1.0 0.00 0.15 p p * (1 − p) Problem 5
sum((1:100)2)
## [1] 338350
Problem 6 x(from =,,) length(x)
## [1] 11
x[2]
## [1] 12
x[1:5]
## [1] 10 12 14 16 18
x[1:3*2]
## [1] 12 16 20
x[1:(3*2)]
## [1] 10 12 14 16 18 20 21. Data in R { Solutions 2 / 4
x
## [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE
x[x]
## [1] 26 28 30
x[-1]
## [1] 12 14 16 18 20 22 24 26 28 30
x[-1:-3]
## [1] 16 18 20 22 24 26 28 30
Problem 7 mean(rivers)
## [1] 591.1844
sd(rivers)
## [1] 493.8708
hist(rivers)Histogram of rivers rivers Frequency
0 1000 2000 3000 4000
40 80 summary(rivers) ## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 135.0 310.0 425.0 591.2 680.0 3710.0
max(rivers)
## [1] 3710
min(rivers)
## [1] 135
rivers[rivers]
## [1] 1459 1450 1243 2348 1171 3710 2315 2533 1306 1054 1270 1885 1100 1205 1038
## [16] 1770 1. Data in R { Solutions3 3 / 4
Problem 8 str(airquality) ##'data.frame': 153 obs. of 6 variables:
## $ Ozone : int 41 36 12 18 NA 28 23 19 8 NA ...
## $ Solar.R: int 190 118 149 313 NA NA 299 99 19 194 ...
## $ Wind : num 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
## $ Temp : int 67 72 74 62 56 66 65 59 61 69 ...
## $ Month : int 5 5 5 5 5 5 5 5 5 5 ...
## $ Day : int 1 2 3 4 5 6 7 8 9 10 ...
153 observations of 6 variables, namedOzone,Solar.R,Wind,Temp,Month,Day. They are all typeintexcept for Wind, which is typenum. Ozone, Solar.R, and Temp would be more natural asnumtypes. Month and Day could be stored as factor types.Problem 9a.table(state.region) ## state.region ## Northeast South North Central West
## 9 16 12 13
b.state.name[state.area] ## [1] "Connecticut" "Delaware" "Hawaii" "Massachusetts" ## [5] "New Hampshire" "New Jersey" "Rhode Island" "Vermont" c.state.name[which.min(state.center$y)] ## [1] "Florida" Problem 10 row.names(mtcars)[mtcars$gear] ## [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Merc 240D" ## [5] "Merc 230" "Merc 280" "Merc 280C" "Fiat 128" ## [9] "Honda Civic" "Toyota Corolla" "Fiat X1-9" "Volvo 142E" row.names(mtcars)[mtcars$gear$am] ## [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Fiat 128" ## [5] "Honda Civic" "Toyota Corolla" "Fiat X1-9" "Volvo 142E" row.names(mtcars)[mtcars$gear$am] ## [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Merc 240D" ## [5] "Merc 230" "Merc 280" "Merc 280C" "Fiat 128" ## [9] "Honda Civic" "Toyota Corolla" "Fiat X1-9" "Porsche 914-2" ## [13] "Lotus Europa" "Ford Pantera L" "Ferrari Dino" "Maserati Bora" ## [17] "Volvo 142E" mean(mtcars$mpg[mtcars$carb]) 41. Data in R { Solutions
- / 4