R version 4.5.2 (2025-10-31 ucrt) -- "[Not] Part in a Rumble" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > 5 > 8 [1] FALSE > > a <- sqrt(2) > a ^ 2 [1] 2 > a^2 == 2 [1] FALSE > a [1] 1.414214 > ?all.equal > all.equal(a^2, 2) [1] TRUE > x <- 20 > !x [1] FALSE > TRUE-0 [1] 1 > FALSE-0 [1] 0 > ls() [1] "a" "x" > rm(list=ls()) #deletes all variabes in current workspace > > > value <- 605 > cvalue <- '605' > value [1] 605 > cvalue [1] "605" > value - cvalue Error in value - cvalue : non-numeric argument to binary operator > cvalue2 <- male Error: object 'male' not found > cvalue2 <- 'male' > as.numeric(value) [1] 605 > as.numeric(cvalue) [1] 605 > as.numeric(cvalue2) [1] NA Warning message: NAs introduced by coercion > cn <- 3+2*i Error: object 'i' not found > 1i [1] 0+1i > lvalue <- TRUE > mode(value) [1] "numeric" > mode(cvalue) [1] "character" > class(value) [1] "numeric" > class(cvalue) [1] "character" > class(lvalue) [1] "logical" > mode(lvalue) [1] "logical" > > > > #my first vector > x <- c(1, 10, 100) > x [1] 1 10 100 > y <- c() > y <- c('james', 'paul', 'maria') > y [1] "james" "paul" "maria" > z <- c(T, F, TRUE) > z [1] TRUE FALSE TRUE > T <- 10 > F <- -20 > z2 <- c(T, F, TRUE) > z2 [1] 10 -20 1 > z3 <- c('james', 10, 20) > z3 [1] "james" "10" "20" > x [1] 1 10 100 > x2 <- c(1000, 10000, 1e6) > c(x,x2) [1] 1e+00 1e+01 1e+02 1e+03 1e+04 1e+06 > a <- 2 > a [1] 2 > a2 <- c(2) > a [1] 2 > a2 [1] 2 > a-a2 [1] 0 > x [1] 1 10 100 > #x again, but now with named elements > x <- c(james=1, paul=10, maria=100) > x james paul maria 1 10 100 > y <- c(2,11,101) #second way to name elements of a vector > names(y) #checking NULL > names(y) <- c('a','b','c') #note character vector > y a b c 2 11 101 > names(y) <- c('d','e','f') #note character vector > y d e f 2 11 101 > x james paul maria 1 10 100 > sum(x) [1] 111 > prod(x) [1] 1000 > length(x) [1] 3 > length(rivers) [1] 141 > mode(rivers) [1] "numeric" > x james paul maria 1 10 100 > names(x) <- NULL > x [1] 1 10 100 > log(x) [1] 0.000000 2.302585 4.605170 > sqrt(x) [1] 1.000000 3.162278 10.000000 > exp(x) [1] 2.718282e+00 2.202647e+04 2.688117e+43 > x > 5 [1] FALSE TRUE TRUE > 2^x [1] 2.000000e+00 1.024000e+03 1.267651e+30 > x <- c(x,0) > x [1] 1 10 100 0 > log(x) [1] 0.000000 2.302585 4.605170 -Inf > rivers [1] 735 320 325 392 524 450 1459 135 465 600 330 336 [13] 280 315 870 906 202 329 290 1000 600 505 1450 840 [25] 1243 890 350 407 286 280 525 720 390 250 327 230 [37] 265 850 210 630 260 230 360 730 600 306 390 420 [49] 291 710 340 217 281 352 259 250 470 680 570 350 [61] 300 560 900 625 332 2348 1171 3710 2315 2533 780 280 [73] 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 [97] 375 1270 545 445 1885 380 300 380 377 425 276 210 [109] 800 420 350 360 538 1100 1205 314 237 610 360 540 [121] 1038 424 310 300 444 301 268 620 215 652 900 525 [133] 246 360 529 500 720 270 430 671 1770 > sort(rivers) [1] 135 202 210 210 215 217 230 230 233 237 246 250 [13] 250 250 255 259 260 260 265 268 270 276 280 280 [25] 280 281 286 290 291 300 300 300 301 306 310 310 [37] 314 315 320 325 327 329 330 332 336 338 340 350 [49] 350 350 350 352 360 360 360 360 375 377 380 380 [61] 383 390 390 392 407 410 411 420 420 424 425 430 [73] 431 435 444 445 450 460 460 465 470 490 500 500 [85] 505 524 525 525 529 538 540 545 560 570 600 600 [97] 600 605 610 618 620 625 630 652 671 680 696 710 [109] 720 720 730 735 735 760 780 800 840 850 870 890 [121] 900 900 906 981 1000 1038 1054 1100 1171 1205 1243 1270 [133] 1306 1450 1459 1770 1885 2315 2348 2533 3710 > order(rivers) [1] 8 17 39 108 129 52 36 42 91 117 133 34 56 87 76 [16] 55 41 75 37 127 138 107 13 30 72 53 29 19 49 61 [31] 103 124 126 46 94 123 116 14 2 3 35 18 11 65 12 [46] 81 51 27 60 78 111 54 43 112 119 134 97 105 102 104 [61] 96 33 47 4 28 73 88 48 110 122 106 139 77 92 125 [76] 100 6 74 95 9 57 93 84 136 22 5 31 132 135 113 [91] 120 99 62 59 10 21 45 86 118 80 128 64 40 130 140 [106] 58 85 50 32 137 44 1 90 79 71 109 24 38 15 26 [121] 63 131 16 82 20 121 89 114 67 115 25 98 83 23 7 [136] 141 101 69 66 70 68 > order(rivers) #HMWK: Explain order() [1] 8 17 39 108 129 52 36 42 91 117 133 34 56 87 76 [16] 55 41 75 37 127 138 107 13 30 72 53 29 19 49 61 [31] 103 124 126 46 94 123 116 14 2 3 35 18 11 65 12 [46] 81 51 27 60 78 111 54 43 112 119 134 97 105 102 104 [61] 96 33 47 4 28 73 88 48 110 122 106 139 77 92 125 [76] 100 6 74 95 9 57 93 84 136 22 5 31 132 135 113 [91] 120 99 62 59 10 21 45 86 118 80 128 64 40 130 140 [106] 58 85 50 32 137 44 1 90 79 71 109 24 38 15 26 [121] 63 131 16 82 20 121 89 114 67 115 25 98 83 23 7 [136] 141 101 69 66 70 68 > > > > x [1] 1 10 100 0 > y <- c(2, 11, 101, 1) > x + y [1] 3 21 201 1 > z <- (3,4) Error: unexpected ',' in "z <- (3," > z <- c(3,4) > x [1] 1 10 100 0 > z [1] 3 4 > x+z [1] 4 14 103 4