1 Mathematical Calculations

Use R calculate the following

  1. 2x53x981x21
2*53*981*21
## [1] 2183706
  1. (95x8734)/47
(95*8734)/47
## [1] 17653.83
  1. \(2^{12}\)
2^12
## [1] 4096

2 Basic R manipulation.

  1. In the code segment below, assign the value 2 to variable x, and the value 6 to variable y. Then compute the sum ‘x+y’:
x = 2
y = 6
x+y
## [1] 8
  1. Construct a list of all even numbers between 1 and 100, assign this to the variable ‘even’. Construct a list of 100 numbers, starting with 1, such that the difference between consecutive numbers is three, assign this to the variable ‘threes’. Construct a list of 100 equally spaced numbers between 0 and 2. Assign this to the variable x.
even = seq(from = 2, to = 100, by = 2)
even
##  [1]   2   4   6   8  10  12  14  16  18  20  22  24  26  28  30  32  34  36  38
## [20]  40  42  44  46  48  50  52  54  56  58  60  62  64  66  68  70  72  74  76
## [39]  78  80  82  84  86  88  90  92  94  96  98 100
threes = seq(from = 1, by = 3, length.out = 100)
threes
##   [1]   1   4   7  10  13  16  19  22  25  28  31  34  37  40  43  46  49  52
##  [19]  55  58  61  64  67  70  73  76  79  82  85  88  91  94  97 100 103 106
##  [37] 109 112 115 118 121 124 127 130 133 136 139 142 145 148 151 154 157 160
##  [55] 163 166 169 172 175 178 181 184 187 190 193 196 199 202 205 208 211 214
##  [73] 217 220 223 226 229 232 235 238 241 244 247 250 253 256 259 262 265 268
##  [91] 271 274 277 280 283 286 289 292 295 298
x = seq(from = 0, to = 2, length.out = 100)
x
##   [1] 0.00000000 0.02020202 0.04040404 0.06060606 0.08080808 0.10101010
##   [7] 0.12121212 0.14141414 0.16161616 0.18181818 0.20202020 0.22222222
##  [13] 0.24242424 0.26262626 0.28282828 0.30303030 0.32323232 0.34343434
##  [19] 0.36363636 0.38383838 0.40404040 0.42424242 0.44444444 0.46464646
##  [25] 0.48484848 0.50505051 0.52525253 0.54545455 0.56565657 0.58585859
##  [31] 0.60606061 0.62626263 0.64646465 0.66666667 0.68686869 0.70707071
##  [37] 0.72727273 0.74747475 0.76767677 0.78787879 0.80808081 0.82828283
##  [43] 0.84848485 0.86868687 0.88888889 0.90909091 0.92929293 0.94949495
##  [49] 0.96969697 0.98989899 1.01010101 1.03030303 1.05050505 1.07070707
##  [55] 1.09090909 1.11111111 1.13131313 1.15151515 1.17171717 1.19191919
##  [61] 1.21212121 1.23232323 1.25252525 1.27272727 1.29292929 1.31313131
##  [67] 1.33333333 1.35353535 1.37373737 1.39393939 1.41414141 1.43434343
##  [73] 1.45454545 1.47474747 1.49494949 1.51515152 1.53535354 1.55555556
##  [79] 1.57575758 1.59595960 1.61616162 1.63636364 1.65656566 1.67676768
##  [85] 1.69696970 1.71717172 1.73737374 1.75757576 1.77777778 1.79797980
##  [91] 1.81818182 1.83838384 1.85858586 1.87878788 1.89898990 1.91919192
##  [97] 1.93939394 1.95959596 1.97979798 2.00000000
  1. Define a function that takes input height and weight, and outputs the BMI for those values of height and weight.
BMI = function (weight, height) {
  bmi = (weight/height^2)*703
  return(bmi)
}
weight1 = 145
height1 = 70

BMI(weight1,height1)
## [1] 20.80306
weight2 = 130
height2 = 67

BMI(weight2,height2)
## [1] 20.35865

Use this function to calculate your BMI.