# Week 1

## Introduction

#### Learning objectives

• Understand statistical programming
• Why R?
• How this course will benefit you

## Fundamentals of R

#### Learning objectives

• Vectors as building blocks
• Vectorization and recycling
• Logical and comparison operators
• Conditional control flow
• Iteration with for, while, and repeat

## Data types and functions

#### Learning objectives

• Atomic vector manipulation
• Creating generic vectors
• Function writing best practices
• Four function forms
• Function scope and lazy evaluation
• Handling reserved words: Inf, NaN, NA

## Exercise of the week

Write a function called seq_fib(). Function seq_fib() should take one argument, n - an atomic numeric vector of length 1, and return the first n Fibonacci numbers as an atomic vector. Some examples of the function in action are given below.

#### Valid inputs

seq_fib(n = 1)
seq_fib(n = 2)
seq_fib(n = 7)
seq_fib(n = 10)

## [1] 0
## [1] 0 1
## [1] 0 1 1 2 3 5 8
##  [1]  0  1  1  2  3  5  8 13 21 34


#### Invalid inputs

seq_fib(n = -2)

## Error in seq_fib(n = -2): n >= 1 is not TRUE

seq_fib(n = c(2, 3, 10))

## Error in seq_fib(n = c(2, 3, 10)): length(n) == 1 is not TRUE


Did you remember to handle situations such as seq_fib(n = 4.9)?

Previous
Next