zapsmall(x, digits = getOption(“digits”)))
If some values of x are nearly zero relative to the larger values in x, then zapsmall will set those small values to zero.
- x – A numeric vector.
- digits – An integer indicating the precision.
While not a perfect rule, anticipate values of x that are, in absolute value, less than 1 and are 10^digits smaller than the largest values of x to be set to zero.
sub(pattern, replacement, x)
gsub(pattern, replacement, x)
Replace the first occurrence of a pattern with sub or replace all occurrences with gsub.
- pattern – A pattern to search for, which is assumed to be a regular expression. Use an additional argument fixed=TRUE to look for a pattern without using regular expressions.
- replacement – A character string to replace the occurrence (or occurrences for gsub) of pattern.
- x – A character vector to search for pattern. Each element will be searched separately.
Skip to the next iteration in a loop.
Retrieve information about packages that have already been installed. For instance, learn the current version, what packages rely on other packages, or the license a package is available under.
by(data, INDICES, FUN, …)
Apply a function across subsets of data, where the subsets are defined by the INDICES argument. The by function returns a list, where each list item represents the results for a particular subset of the data.
- data – The full set of data, e.g. a vector or data.frame.
- INDICES – A vector describing how the data subsets are to be constructed (e.g. a factor vector). Multiple columns in a data frame may also be given, where each combination of the variables defines a new subset of data.
- FUN – A function to apply to each subset of data.
- … – Any additional arguments to pass to FUN.
function is used to split a plotting window into different rectangular sections called "screens". This is similar to what par(mfrow)
does, but it is more general since it allows for some plots to span rows and columns. The screen
function is used to select a screen for adding a plot and screen
also makes it possible to move back and forth between the screens.
- figs – Describe the number of rows and columns for a new plot via a numeric vector of length 2. Or, if the screen argument is also set, then specify how that specified screen should be split.
- screen – If a screen is to be split into pieces, specify the screen number.
- n – The number of the screen to which plotting commands should be assigned.
Examine which commands are taking up the most time in an R script or function. I’d call this a crapshoot since Rprof doesn’t typically indicate a particular line of code that is taking a disproportionate amount of time. However, Rprof is easy and quick to implement, so it may serve as a nice first attempt to identify what is making code run slowly.
- filename – A file name where to store results.
Create a character string that contains values from R objects. (The sprintf is much more robust than is touched on here, but this will provide sufficient info for a basic start.)
- fmt – A character string with some occurrences of %s, which will be places that object values are inserted.
- … – The R objects to be inserted. The number of items should correspond to the number of %s occurrences in fmt.
lapply(X, FUN, …)
Apply a function across each item in a list. The returned object is a list, where each item is the output corresponding to that item in the original list.
- X – A list.
- FUN – A function.
- … – Additional arguments, if necessary, to pass to FUN.
Unlist a list of vectors into a single vector. This function will also unlist all lists within the list as well, but this setting may be turned off via additional options.