1.1
1+2*(3+4)
## [1] 15
4^3+3^(2+1)
## [1] 91
sqrt((4+3)*(2+1))
## [1] 4.582576
((1+2)/(3+4))^2
## [1] 0.1836735
1.2
\((2+3)-4\)
\(2+(3\times4)\)
\((2 \div 3) \div 4\)
\(2^{(3^4)}\)
1.3
(1+2*3^4)/(5/6-7)
## [1] -26.43243
1.4
(0.25-0.2)/sqrt(0.2*(1-0.2)/100)
## [1] 1.25
1.5
x1<-2; x2<-3; x3<-4; x4<-5
x <- x1*x2*x3*x4
# show the result
x
## [1] 120
1.6
data("rivers")
rivers
## [1] 735 320 325 392 524 450 1459 135 465 600 330 336 280 315
## [15] 870 906 202 329 290 1000 600 505 1450 840 1243 890 350 407
## [29] 286 280 525 720 390 250 327 230 265 850 210 630 260 230
## [43] 360 730 600 306 390 420 291 710 340 217 281 352 259 250
## [57] 470 680 570 350 300 560 900 625 332 2348 1171 3710 2315 2533
## [71] 780 280 410 460 260 255 431 350 760 618 338 981 1306 500
## [85] 696 605 250 411 1054 735 233 435 490 310 460 383 375 1270
## [99] 545 445 1885 380 300 380 377 425 276 210 800 420 350 360
## [113] 538 1100 1205 314 237 610 360 540 1038 424 310 300 444 301
## [127] 268 620 215 652 900 525 246 360 529 500 720 270 430 671
## [141] 1770
1.7
# Load the related packages
library(MASS)
library(HistData)
library(lattice)
library(survival)
library(Formula)
library(ggplot2)
library(Hmisc)
library(UsingR)
data("exec.pay")
exec.pay
## [1] 136 74 8 38 46 43 9 9 12 11 20 9 95 34
## [15] 7 14 39 12 29 21 60 35 17 36 29 162 88 31
## [29] 6 135 13 20 9 14 28 42 10 35 2 16 28 42
## [43] 142 33 134 23 34 16 13 167 9 22 39 28 30 22
## [57] 14 9 25 106 32 30 89 89 47 17 26 1231 6 103
## [71] 48 24 11 19 13 29 20 45 3 33 41 7 11 10
## [85] 22 36 7 19 41 40 10 15 93 67 29 25 91 38
## [99] 2510 5 32 65 0 13 27 16 21 6 0 28 8 13
## [113] 71 36 11 106 37 41 13 900 38 24 15 27 12 12
## [127] 22 40 49 22 118 48 10 1 36 155 9 34 29 12
## [141] 0 28 21 32 18 52 29 13 199 40 11 51 45 43
## [155] 31 5 18 15 25 9 18 13 58 22 40 34 16 31
## [169] 27 15 23 49 60 28 74 42 24 17 9 61 20 23
## [183] 26 31 167 19 14 13 146 283 12 53 26 16 29 51
## [197] 15 22 27
1.8
mean(exec.pay); min(exec.pay); max(exec.pay)
## [1] 59.88945
## [1] 0
## [1] 2510
1.9
mean(exec.pay); mean(exec.pay, trim = 0.1)
## [1] 59.88945
## [1] 29.96894
1.10
data("Orange")
# return the names of three variables
names(Orange)
## [1] "Tree" "age" "circumference"
1.11
mean(Orange$age)
## [1] 922.1429
1.12
max(Orange$circumference)
## [1] 214
1.18
x = c(1, 3, 5, 7, 9)
y = c(2, 3, 5, 7, 11, 13)
x+1
## [1] 2 4 6 8 10
y*2
## [1] 4 6 10 14 22 26
length(x); length(y)
## [1] 5
## [1] 6
x+y
## Warning in x + y: longer object length is not a multiple of shorter object
## length
## [1] 3 6 10 14 20 14
sum(x>5); sum(x[x>5])
## [1] 2
## [1] 16
sum(x>5|x<3)
## [1] 3
y[3]
## [1] 5
y[-3]
## [1] 2 3 7 11 13
y[x]
## [1] 2 5 11 NA NA
y[y>=7]
## [1] 7 11 13
1.19 Consider the following “inequalities.” Can you determine how the comparisons are being done?