Transcription of Introduction to the R Language - Functions
{{id}} {{{paragraph}}}
Introduction to the R LanguageFunctionsBiostatistics R LanguageFunctionsFunctions are created using thefunction()directive and arestored as R objects just like anything else. In particular, they are Robjects of class function .f <- function(<arguments>) {## Do something interesting} Functions in R are first class objects , which means that they canbe treated much like any other R object. Importantly, Functions can be passed as arguments to other functionsFunctions can be nested, so that you can define a functioninside of another functionThe return value of a function is the last expression in the functionbody to be R LanguageFunction ArgumentsFunctions havenamed argumentswhich potentially argumentsare the arguments included in thefunction definitionTheformalsfunction returns a list of all the formalarguments of a functionNot every function call in R makes use of all the formalargumentsFunction arguments can bemissingor might have defaultvaluesThe R LanguageArgument MatchingR Functions arguments can be matched positionally or by name.
x^2 + y / z} This function has 2 formal arguments x and y. In the body of the function there is another symbol z. In this case z is called a free variable. The scoping rules of a language determine how values are assigned to free variables. Free variables are not formal arguments and are not local variables (assigned insided the function body ...
Domain:
Source:
Link to this page:
Please notify us if you found a problem with this document:
{{id}} {{{paragraph}}}