| Start |
|---|
| Anonymous functions 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 Calculate the root mean square for each column in a Create a sequence of step-length one from the smallest to the largest value for each row in a matrix. An anonymous function can also stand on its own: is equivalent to |
| RStudio code snippets This is just a small hack for those who use self-defined functions often. The result will be a skeleton of a new function. One can easily define their own snippet template, i.e. like the one below The option is |
| Named functions R is full of functions, it is after all a functional programming language (opens new window), but sometimes the precise function you need isn't provided in the Base resources. You could conceivably install a package (opens new window) containing the function, but maybe your requirements are just so specific that no pre-made function fits the bill? Then you're left with the option of making your own. A function can be very simple, to the point of being being pretty much pointless. It doesn't even need to take an argument: What's between the curly braces A function can be very simple, yet highly specific. This function takes as input a vector ( Notice that
The above are all examples of named functions, so called simply because they have been given names ( |
| Passing column names as argument of a function 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 As a result of running above given code, names of selected variables and their basic summary statistics (minima, first quantiles, medians, means, third quantiles and maxima) are printed in R console. The code |
Read Article
https://develop.horje.com/learn/1434/reference