Programming Deep Dive 2

Prof. Dr. Mirco Schoenfeld

R

yay

conditions

First basic concept:

Conditional Code Execution

It’s your turn

  1. Create a R script.
  2. Define a variable something_wrong <- FALSE.
  3. Use an if-then-else-block to print a message if ‘something is wrong’ meaning if something_wrong is True or False.
  4. Add the script to your git repository.
  5. Commit the changes.

Useful resources:

First 12 minutes of this video

“Executing Code Conditionally”: https://mircoschoenfeld.de/software-technology-and-applied-programming.html#programming-deep-dive

loops

Second basic concept:

Loops.

It’s your turn

  1. Create a R script.
  2. Define a vector that will hold the results.
  3. Define a for-loop that runs from 1 to 100.
  4. Inside the loop, multiply the index of the current iteration by 2 and append it to the result list.
  5. OPTIONAL: create the sum of the running index and the value of the previous field in the result list. Store the sum.
  6. Add the script to your git repository.
  7. Commit the changes.

Useful resource: This video

“for-loops”: https://mircoschoenfeld.de/software-technology-and-applied-programming.html#programming-deep-dive

functions

Last basic concept:

Functions.

It’s your turn

  1. Create a R script.
  2. Define a function that converts a value in Celsius to Fahrenheit.
  3. Add the script to your git repository.
  4. Commit the changes.

Useful resource: This video

“Functions accepting parameters”: https://mircoschoenfeld.de/software-technology-and-applied-programming.html#programming-deep-dive