In this exercise/assignment, we will learn how to perform basic operations using R while at the same time familiarising ourselves with using RStudio and with using a project-orientated R workflow.
For this exercise, we will use body mass index or BMI as our topic of interest and will use R in performing BMI calculations.
Given a person with a weight of 80 kilograms and a height of 1.6 metres, calculate BMI using R.
-
What is the formula for calculating BMI? What are the typical/standard units used for weight and height for this calculation?
-
What are the arithmetic/mathematical operations expressed in the BMI formula? What symbols or syntax are used in R to perform the operations in the BMI formula?
-
How to issue the command/instructions to R to perform the operations to calculate BMI?
-
How to record/store the output of the command/instructions issued to R to perform the operations to calculate BMI?
-
How to record/store/save the command/instructions issued to R to perform the operations to calculate BMI?
Say we have Person A with a weight of 80 kilograms and a height of 1.6 metres and Person B with a weight of 120 kilograms and a height of 210 centimetres.
In R, try to answer the following questions:
-
Is Person A heavier in weight compared to Person B?
-
Is Person A taller in height compared to Person B?
-
Whose BMI is greater, Person A or Person B?
In R, answer the following questions using logical operators:
-
Is the weight of Person A AND the weight of Person B both equal to 80 kilograms?
-
Is the weight of Person A OR the weight of Person B less than 100 kilograms?
-
Is the weight of Person A greater than the weight of Person B AND the height of Person A greater than the height of Person B?
-
Is the weight of Person A greater than the weight of Person B OR the height of Person A greater than the height of Person B?