Tutorial by Examples

R is full of functions, it is after all a functional programming language, but sometimes the precise function you need isn't provided in the Base resources. You could conceivably install a package containing the function, but maybe your requirements are just so specific that no pre-made function fit...
An anonymous function is, as the name implies, not assigned a name. This can be useful when the function is a part of a larger operation, but in itself does not take much place. One frequent use-case for anonymous functions is within the *apply family of Base functions. Calculate the root mean squ...
This is just a small hack for those who use self-defined functions often. Type "fun" RStudio IDE and hit TAB. The result will be a skeleton of a new function. name <- function(variables) { } One can easily define their own snippet template, i.e. like the one below ...
Sometimes one would like to pass names of columns from a data frame to a function. They may be provided as strings and used in a function using [[. Let's take a look at the following example, which prints to R console basic stats of selected variables: basic.stats <- function(dset, vars){ f...

Page 1 of 1