Take control!
In this exercise, you will combine everything that you've learned so far: relational operators, logical operators and control constructs. You'll need it all!
We've pre-defined two values for you: li
and fb
, denoting the number of profile views your LinkedIn and Facebook profile had on the last day of recordings. Go through the instructions to create R code that generates a 'social media score', sms
, based on the values of li
and fb
.
This exercise is part of the course
Intermediate R
Exercise instructions
Finish the control-flow construct with the following behavior:
- If both
li
andfb
are 15 or higher, setsms
equal to double the sum ofli
andfb
. - If both
li
andfb
are strictly below 10, setsms
equal to half the sum ofli
andfb
. - In all other cases, set
sms
equal toli + fb
. - Finally, print the resulting
sms
variable.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Variables related to your last day of recordings
li <- 15
fb <- 9
# Code the control-flow construct
if (___ & ___) {
sms <- 2 * (li + fb)
} ___ (___) {
sms <- 0.5 * (li + fb)
} else {
sms <- ___
}
# Print the resulting sms to the console