John Miyamoto - University of Washington
John Miyamoto
Useful R Commands (Top); Useful R Information Sources (Bottom)
Contents (Cntrl-left click on a link to jump to the corresponding section)
|Section |Topic |
|1RefTo: s1 |Useful R Functions |
|2RefTo: s0001 |Notes re plot and lines |
|3RefTo: s1b |Regular expressions in R |
|4RefTo: s6 |Special characters like "\n" |
|5RefTo: s2 |Useful Links and Documents (Bookmarks: 's2', 'Links', 'Docs') |
|6RefTo: s5 |Notes re the Built-In R Editor |
|7RefTo: s3 |Possible Editors for R Programming |
|8RefTo: s4 |Notes on R-Code/Computing (see also 'e:\r\notes' and 'e:\r\docs') |
1s1. Useful R Functions
|Function |Purpose |
|"imputation" |See packages 'cat', 'norm', and 'mix' for various imputation functions. See, also, the |
| |'transcan' function in the 'Hmisc' package. See, also, |
| |. |
|%in% |If X and Y are vectors, X %in% Y is a vector. length(X %in% Y) = length(X). The i-th element |
|match |of X %in% Y equals TRUE if X[i] is an element of Y and is FALSE otherwise. The match function |
| |serves similar purposes but is more easily modified. |
|.libPaths |.libPaths gets/sets the library trees within which packages are looked for. '.libPaths(new)' |
| |where 'new' is a character vector with the locations of R library trees. |
|.Platform |.Platform is a list with some details of the platform under which R was built. This provides |
|R.version |means to write OS portable R code. E.g., '.Platform$Os.type' gives the operating system that |
|() |the current version was written for. See also 'R.version' and '()'. |
| |The operators cause a search to made through the environment for an existing |
| |definition of the variable being assigned. If such a variable is found then its value is |
| |redefined, otherwise assignment takes place globally. Note that their semantics differ from that|
| |in the S language, but is useful in conjunction with the scoping rules of R. |
|all.equal |all.equal(x,y) is a utility to compare R objects x and y testing ``near equality''. If they are |
| |different, comparison is still made to some extent, and a report of the differences is returned.|
| |Don't use 'all.equal' directly in if expressions—either use 'identical' or combine the two, as |
| |shown in the documentation for 'identical'. See also 'identical' and '=='. |
|AnalyzeFMRI |Package for analyzing fMRI images. |
|arrows |Draw arrows between pairs of points. Also useful for creating error bars (set 'angle' to 90). |
|barplot |Makes bar plots. Note that 'x.loc gl(3,4) |
| |[1] 1 1 1 1 2 2 2 2 3 3 3 3 |
| |Levels: 1 2 3 |
|glm( ..., family = binomial) |Logistic regression. Note that the summary function gives results in the log odds ratio form. |
| |You need to transform back to odds ratios. |
|head |Returns the first or last parts of a vector, matrix, data frame or function. Useful for viewing|
| |or extracting a small subset of cases. |
|head |Returns the first few rows of a dataframe or matrix (or vector). |
|help.search |Searches the R help system for documentation matching a given character string in the (file) |
| |name, alias, title, concept or keyword entries (or any combination thereof), using either fuzzy |
| |matching or regular expression matching. Names and titles of the matched help entries are |
| |displayed nicely. See also 'RSiteSearch'. |
|identical |The safe and reliable way to test two objects for being exactly equal. It returns TRUE in this |
| |case, FALSE in every other case. See also 'all.equal' and '=='. |
|ifelse(test, yes, no) |'ifelse' returns a value with the same shape as test which is filled with elements selected from|
| |either 'yes' or 'no' depending on whether the element of 'test' is TRUE or FALSE. |
|image |Creates a grid of colored or gray-scale rectangles with colors corresponding to the values in z.|
| |This can be used to display three-dimensional or spatial data aka images. |
|image |Creates a grid of colored or gray-scale rectangles with colors corresponding to the values in z.|
| |This can be used to display three-dimensional or spatial data aka “images”. This is a generic |
| |function. The functions heat.colors, terrain.colors and topo.colors create heat-spectrum (red to|
| |white) and topographical color schemes suitable for displaying ordered data, with n giving the |
| |number of colors desired. |
|interaction.plot |Makes a line plot for a 2-way anova design with one factor on the X axis and the other factor |
| |with separate lines. |
|isoMDS (in MASS) |Alternative functions that perform nonmetric multidimensional scaling (mds). |
|sammon (in MASS) | |
|cmdscale (in mva) | |
|xgvis (in xgobi) | |
|layout |Used for making multiple graphs on a single screen (like mfrow or mfcol). Unlike mfrow or |
| |mfcol, row and column heights can be specified for individual rows or columns. |
|library('package name') |Loads 'package name'. |
|library(help = MASS) |Lists all objects in MASS along with short description. |
|ls(package:MASS) |Lists all objects in MASS if it is attached. |
|lines |Add lines and points to a plot. See Section 2RefTo: s0001 for more info. |
|list.files |This function produces a list containing the names of files in the named directory. dir is an |
| |alias. key = filenames |
|logtrans |MASS package: Find and optionally plot the marginal likelihood for alpha for a transformation |
| |model of the form log(y + alpha) ~ x1 + x2 + .... |
|make.names |Make syntactically valid names out of character vectors. |
|make.unique |Makes the elements of a character vector unique by appending sequence numbers to duplicates. |
| |Useful for creating unique names of variables or factor levels. |
|match.call |match.call returns a call in which all of the arguments are specified by their names. The most |
| |common use is to get the call of the current function, with all arguments named, i.e., use |
| |'match.call' if you want to return the current values of the parameters that were input to a |
| |function. |
|merge |Analogous to the SPSS command, JOIN MATCH / TABLE. |
| |Combines input dataframes on common values for columns with identical names or user-specified |
| |columns. |
|mvrnorm |MASS package: Generates multivariate normal random variables. |
|mvtnorm |'mvtnorm' package generate probabilities under a multivariate normal density function. Can be |
| |used to generate data with a given variance/covariance matrix (use 'rmvnorm'). Also, look at |
| |'mvrnorm' in the MASS package. |
|n.gt.1 |JM function that counts the number of cases in each condition (combination of factor levels) in |
| |a multifactor between subjects anova. The output is TRUE if the condition has more than 1 |
| |observation and FALSE if it has 0 or 1 observation. This function is useful in combination with|
| |'studres' in the MASS library because this function sometimes yields a value of 0 where it |
| |should be NA when a cell has only 1 observation. |
|na.omit |Omits cases from a dataframe if any variables have missing data. |
|onecode |JM function that creates a oneway anova factor from multiple input factors. 'onecode' is useful|
| |whenever it is easer to treat a multifactor between subects anova as a oneway anova. |
|oneway.test |Computes a oneway anova (between subjects). Default is to NOT assume homogeneity of variance. |
|optimize |The function optimize searches the interval from lower to upper for a minimum or maximum of the |
| |function f with respect to its first argument. |
|p.adjust |Multiple comparison procedure: Given a set of p values, returns p values adjusted using Holm |
| |method (default), Hochberg method, or Bonferroni method (in the base package). |
|'package functions' |These functions can be used to automatically compare the version numbers of installed packages |
|update.packages |with the newest available version on the repositories and update outdated packages on the fly. |
|available.packages | |
|old.packages | |
|new.packages | |
|download.packages | |
|install.packages | |
|contrib.url | |
|package.skeleton |'package.skeleton' automates some of the setup for a new source package. It creates directories,|
| |saves functions and data to appropriate places, and creates skeleton help files and ‘README’ |
| |files describing further steps in packaging. |
|pairs() |Produces all pairs of scatter plots. |
|pairwise.prop.test |Multiple comparison procedures for various tests (in the ctest package). |
|pairwise.t.test | |
|pairwise.table | |
|pairwise.wilcox.test | |
|par("mai") |A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified|
| |in inches. (Use 'mai' or 'mar' but not both.) |
|par("mar") |A numerical vector of the form 'c(bottom, left, top, right)' which gives the number of lines of |
| |margin to be specified on the four sides of the plot. The default is 'c(5, 4, 4, 2) + 0.1'. |
|par("mex") |'mex' is a character size expansion factor which is used to describe coordinates in the margins |
| |of plots. Note that this does not change the font size, rather specifies the size of font used |
| |to convert between 'mar' and 'mai', and between 'oma' and 'omi'. (Note that JM has been |
| |misusing this parameter until 8/21/2005.) |
|par("usr") |Gives the min and max on the x and y axis for the current plot. |
|par("xpd") |Logical. If FALSE, all plotting is clipped to the plot region, if TRUE, all plotting is clipped|
| |to the figure region, and if NA, all plotting is clipped to the device region. Can be used to |
| |put legend (or any other text) outside of the plotting region. |
|permn |In 'combinat' package. Generates all permutations of the elements of x, in a minimal- change |
| |order. If x is a positive integer, returns all permutations of the elements of seq(x). If |
| |argument "fun" is not null, applies a function given by the argument to each point. "..." are |
| |passed unchanged to the function given by argument fun, if any. |
|plot |Create plots. See Section 2RefTo: s0001 for more info. |
|power.prop.test |Computes power of test for equality of proportions, or determines parameters to obtain target |
| |power. |
|power.t.test |Compute power of test, or determine parameters to obtain target power. |
|proc.time |proc.time determines how much time (in seconds) the currently running R process already |
| |consumed. Value: A numeric vector of length 5, containing the user, system, and total elapsed |
| |times for the currently running R process, and the cumulative sum of user and system times of |
| |any child processes spawned by it. See also 'system.time' and 'gc'. |
|ptukey |Functions for the studentized range distribution. |
|qtukey | |
|qr |qr computes the QR decomposition of a matrix. The QR decomposition plays an important role in |
| |many statistical techniques. In particular it can be used to solve the equation Ax = b for given|
| |matrix A, and vector b. It is useful for computing regression coefficients and in applying the |
| |Newton-Raphson algorithm. The functions qr.coef, qr.resid, and qr.fitted return the |
| |coefficients, residuals and fitted values obtained when fitting y to the matrix with QR |
| |decomposition qr. qr.qy and qr.qty return Q %*% y and t(Q) %*% y, where Q is the Q matrix. |
|range |range usually returns the min and max of a vector, but see the following example for an |
| |illustration of how range deals with missing and infinite elements: |
| |x none, I can't get just one "\" where I need it. See example code |
|> below. I am using R 2.1.0, but plan to upgrade soon. Thanks in |
|> advance to anyone who can help. |
|> Roger |
|> |
|> rankPath rankDate rankFile rankFile |
|> [1] "R:New RanksSMCSMC20050819.xls" |
|> |
|> rankPath rankDate rankFile rankFile |
|> [1] "R:\\New Ranks\\SMC\\SMC20050819.xls" |
| |
|This is perfect, "\" is *printed* escaped, hence for file access you can perfectly use this character vector. |
|Uwe Ligges |
|... and you can see that the "\\" is correct by cat(rankFile) instead of print(rankFile), which is what entering the variable at the prompt |
|actually does. |
|-- Bert Gunter |
|**JM: The '\\' is printed in the second example, but it denotes the correct path and file as far as R is concerned. |
|'update packages' |
|Problem: Has anyone written a script to inspect a previous installation, then get & install the same packages into the new installation? |
|# Solution from Uwe Ligges. |
|x foo as.vector(foo[is.na(foo[, "Priority"]), 1]) |
| |
|will give you a character vector which you can feed to install.packages(), |
|so it's not complex to do manually. |
|'Type I sum of squares', 'Type II sum of squares', 'Type III sum of squares' |
|The 'base' function 'anova' computes Type I SS's. The 'car' function 'Anova' computes Type II and Type III SS's. |
Keywords followed by Note
************************************************************************
-----------------------
[1] From R. Ripley's R course, , see her "R Programming 2010-11".
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- university of washington hr jobs
- university of washington jobs listing
- university of washington human resources
- university of washington human resources dept
- university of washington baseball roster
- university of washington product management
- university of washington online mba
- university of washington printable map
- university of washington opioid taper
- university of washington opioid calculator
- university of washington program management
- university of washington graduate programs