Wednesday 2 August 2017

Functions in R

  1. Functions

  1. Function accepts N number of inputs and provides one output
  2. Functions works like a black box

  3. Function arguments matching :  by position or by name
  4. Function arguments can have defaults
vec <-c(10,30,40,50,20)
sd(vec)
vec <-c(10,30,40,50,20,NA)
sd(vec)
sd(x=vec,na.rm=TRUE) #by value
sd(vec,TRUE) #by position
sd()

  1. What is the default value of na.rm argument? FALSE
  2. How to see arguments of a function?
  3. Exercise 1: create function with one mandatory argument
    1. Method 1:
    2. Method 2:

  1. Exercise 2: create function with two mandatory arguments
  1. Exercise 3: create function with one mandatory arguments and one optional argument

No comments:

Post a Comment