4) Functions and Conditionals

๐Ÿ“– Lecture

You donโ€™t need to be an expert programmer to be a data scientist, but learning more about programming allows you to automate common tasks, and solve new problems with greater ease.

This week weโ€™ll discuss how to write basic functions, the notion of compound expressions in R, and an introduction to conditionals (i.e. if-else statements).

๐Ÿ“š Reading

Read chapters 10, 11, and 12 of โ€œR Coding Basicsโ€:

๐Ÿ”ฌ Lab

You will get your hands โ€œdirtyโ€ writing basic functions, and conditional statements.

๐ŸŽฏ Objectives

At the end of this week you will be able to:

  • Describe the main parts of a function (i.e. anatomy of a function)
  • Give a simple example for creating a function
  • Explain the concept of an R compound expression
  • Write if-else statements to handle simple conditions
  • Use if-else statements when writing functions to decide what code to execute

๐Ÿ”† Shiny Friday

The shiny app for this week is a modified version of the default โ€œOld Faithfulโ€ app.

The main modification has to do with the use of an if-statement to decide whether to display additional statistics on the histogram of waiting times.

More specifically, we have three new versions:

๐Ÿ”” Assignments

  • HW2 due this 02/09
  • HW3 released on 02/10, due 02/16