head, tail

Obtain the first several rows of a matrix or data frame using head, and use tail to obtain the last several rows. These functions may also be applied to obtain the first or last values in a vector.
head(x, n=6)
  • x – A matrix, data frame, or vector.
  • n – The first n rows (or values if x is a vector) will be returned.
tail(x, n=6)
  • x – A matrix, data frame, or vector.
  • n – The last n rows (or values if x is a vector) will be returned.

Continue reading

merge

merge(x, y, all=FALSE)
Merge two data frames together. The use described here assumes that the two data frames being merged have one common column name. The Tip describes how to handle other scenarios.
  • x – Data frame to be merged with y
  • y – Data frame to be merged with x
  • all – Indicate whether to include all rows from both data frames. The default (FALSE) specifies that only the rows that share a common ID in the overlapping column should be included.

Continue reading

smoothScatter

smoothScatter(x, y, bandwidth, nrpoints=100)
Create a density plot of bivariate data using smoothScatter.
  • x – Numeric vector for x-coordinate.
  • y – Numeric vector for y-coordinate.
  • bandwidth – A vector of length 1 or 2 specifying the bandwidth in the kernel density estimate. A default bandwidth will be chosen if this argument is not specified.
  • nrpoints – The number of points to explicitly show on the plot.

Continue reading

ifelse

ifelse(test, yes, no)
The ifelse function is used to assign one object or another depending on whether the first argument, test, is TRUE or FALSE. It even works as one would hope when test is a vector.
  • test – A logical expression, which may be a vector.
  • yes – What to return if test is TRUE.
  • no – What to return if test is FALSE.

Continue reading

apply

apply(x, margin, function, …)
apply implements a function across the rows or columns of a matrix. It also works on multidimensional arrays and can be used to apply functions across one or more dimensions of those arrays.
  • x – A matrix or array.
  • margin – The dimension of the matrix or array x to preserve. If x is an array, then this may be a vector indicating each dimension that should be preserved.
  • function – A function (e.g. mean) to be applied across each dimension not listed in margin. In a matrix, the function would be applied across the rows or columns of x, whichever dimension is not listed in the margin argument.

Continue reading

txtProgressBar, setTxtProgressBar

Create a progress bar for a loop using the txtProgressBar function, then use the setTxtProgressBar command within the loop to print the progress bar, which updates as the loop progresses.
txtProgressBar(min, max, style=1)
  • min – The minimum value in the loop.
  • max – The maximum value in the loop.
  • style – A number representing the style, where 3 is my favorite.
setTxtProgressBar(pb, value)
  • pb – A progress bar object that was output from txtProgressBar.
  • value – The current iteration value.

Continue reading

save, save.image, load

Save a particular set of objects using save, or save all objects in the current R session via save.image. Load an R data file into a session using load.
save(…, file)
  • – List all objects that should be saved.
  • file – Provide the file name, typically ending in .rda. Also, because the list of objects to save is arbitrarily long, the file argument must begin with the argument name, i.e. include file= in this argument’s declaration.
save.image(file)
  • file – Provide the file name, typically ending in .rda or .RData.
load(file)
  • file – The name of the file to be loaded.
In each case, the file name may also include a path to the file.

Continue reading