#Loop print(paste("The year is", 2010)) print(paste("The year is", 2011)) print(paste("The year is", 2012)) print(paste("The year is", 2013)) print(paste("The year is", 2014)) print(paste("The year is", 2015)) #basic loop structure #for(){ #} for (year in c(2010,2011,2012,2013,2014,2015)){ print(paste("The year is", year)) } for (year in 2010:2015){ print(paste("The year is", year)) } for (i in 2010:2015){ print(paste("The year is", i)) } for (i in 1:10) { if (!i %% 2){ next } print(i) } #Function #myfunction <- function(arg1, arg2, ... ){ # statements # return(object) #} yas <- function(x){ return(x^2) } yas(2) ck <- function(x){ return(x+2) } ck(yas(2)) foam <- function(x,y,z){ print(paste("hello", x, y+z)) } foam(1,2,3) # Exercise (20 minutes) # y = sin^x # z = call option formula # a = coupon bond