-1

Write a function called dayplan(temperature,work). The Function should at first check if it is dealing with realistic values. Thereby temperature∈[-20,40] and work∈{´Yes´, ´No´}. For realistic values the function should give out these values:

When temperature>=20 and job==´Yes´, then "Eat ice cream"

When temperature>=20 and job==´No´, then "Sea"

When temperature >20 and job ==´Yes´, then "Shopping"

When temperature<20 and job==´No´, then "Bed"

Lira
  • 1
  • 2

1 Answers1

0

The outline of the function can look something like this:

dayplan <- function(temperature, work){
  if(...){
    if(...){
      print("Eat ice cream.")
    } else if(...) {
       ...
       ...
    }
  } else {
    print("Inputs not feasible.")
  }
}

Fill in the gaps using the conditions for each activity.

Kenneth Rios
  • 146
  • 4
  • Hey, so I don't really know how to incorporate the "Shopping" and "Bed" options into this. Also, do I need to set the limit for temperature under 40? dayplan <- function(temperature, work){ if(temperature>=20){ if(work='Yes'){ print("Eat ice cream.") } else if(work='No') { print("Sea") ... } } else { print("Inputs not feasible.") } } – Lira Jan 20 '18 at 06:47
  • According to what you wrote, temperature should be less than or equal to 40 but greater than or equal to -20. For your first question, it's the same thing as the ice cream option: use the print() function. – Kenneth Rios Jan 20 '18 at 07:00
  • Hey, sorry but this is what I have in the end and it isn't really working. dayplan <- function (temperature, work) { if(temperature>=20) { if(work=='Yes') { print("Eat ice cram") } else if (work == 'Non') { print("Sea") } else if(temperature < 20) { if(work == 'Yes') { print("Shopping") } } else if (work == 'No'){ print("Bed") } } else { print("Input not feasible") } – Lira Jan 20 '18 at 13:49
  • That's not how it works. I suggest you read up on how ifelse statements work in R. – Kenneth Rios Jan 20 '18 at 14:46