Lec8 Programming in R Functions
Lec8 Programming in R Functions
Lec8 Programming in R Functions
In this lecture
Functions
◦ MIMO
Source (load) and call (invoke)
Inline functions
Looping over objects
◦ apply
◦ lapply
◦ tapply
Diameter Volume
volcylinder_mimo
Height list(volume, surface area)
Surface area
4. Execute
Inline functions
Example of an inline function
apply function
Applies a given function over the margins of a
given array.
◦ Syntax: apply(array, margins, function,…)
◦ Here margins refer to the dimension of the array
along which the function need to be applied.
lapply function
lapply is used to apply a function over a list.
lapply always returns a list of the same
length as the input list
◦ Syntax: lapply(list, function, …)
mapply function
• mapply is a multivariate version of lapply.
• A function can be applied over several lists
simultaneously.
◦ Syntax: mapply(fun, list1, list2, …)
tapply function
tapply is used to apply a function over subset of
vectors given by a combination of factors
◦ Syntax: tapply(vector, factors, function, …)