Exercise
Exercise
Exercise
I. The R terminal
a. The R terminal is where the commands can be entered and the results
displayed
b. > R prompt means R is waiting for you to do something
i. 2+2
ii. 6*5
iii. # 3-2
c. Points to be noted –
i. Spaces don’t matter
ii. Standard arithmetic operators + , -, / are as expected
iii. All expressions followed by # are not evaluated as # is used to add a
comment in R programming
III. Vectors
a. A vector is a sequence of data elements of the same basic type
b. Function –c – it concatenates values together.
c. sms < - c(0,1,2,0,0,0,1)
d. Function c is followed by parenthesis which contain the arguments to the
function.
e. All mathematical operations can be done on these vectors through R
f. sms +5
g. sms *5
IV. Other functions
a. sd()
b. median()
c. max()
d. min ()
e. length() – number of elements in the vector
Exercises
3. The numbers below are the first ten days of rainfall amounts in centimeter. Read them into
a vector rainfall
0.1, 0.6, 33.8, 1.9, 9.6, 4.3, 33.7, 0.3, 0.0, 0.1
4. Assume that we have registered the height and weight for four people: Heights in cm are
180, 165, 160, 193; weights in kg are 87, 58, 65, 100. Make two vectors height and weight with
the data. The body mass index (BMI) is defined as weight in kg/(height in m2). Make a vector
with the BMI values for the four people, and a vector with the natural logarithm to the BMI
values. Finally make a vector with the weights for those people who have a BMI larger than
25.