These exercises are about the functions sections of Introduction to R.

Exercise 1 - Functions

– Create a function which takes one number and returns the square of that number

## [1] 9

– Create a function which takes two numbers and returns the mean

## [1] 2
## The total length of my vectors is 8
## [1] 4.25
## [[1]]
## [1] 1 3
## 
## [[2]]
##   mean sum multiple
## 1    2   4        3

– Create a function which takes one argument and finds the smallest number whose factorial is greater than that argument.

## [1] 7
## [1] 70

– Add a if and else statement in your function to only calculate factorial code if argument is a numeric.

## [1] 7
## Please provide a numeric argument!

Exercise 2 - Scripts

Lets try to put as much together that we have learnt thus far. This will be a multistep challenge. Break it down and use pseudocode to help. Start by working the code interactively, then turn it into a script.

  1. Read in the “data/GeneExpression.txt” dataset.
  2. Use a apply to calculate the Z score for each gene (per row). The zscore is (gene_expression - mean)/standard deviation. You should use a function to do this calculation.
  3. Find which gene has the highest absolute max Zscore. This is a very rough proxy for the variability of that gene.
  4. Print out the gene name with the highest value
  5. Turn this into a script and run the script
  6. Think about what modifications you would need to make in order to accept a different data set as input.
## [1] "Gene_h"