sub, gsub

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.

Continue reading

by

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.

Continue reading

split.screen, screen

The split.screen 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.
split.screen(figs, screen)
  • 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.
screen(n)
  • n – The number of the screen to which plotting commands should be assigned.

Continue reading

Rprof

Rprof(filename)
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.

Continue reading

sprintf

sprintf(fmt, …)
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.

Continue reading