If you are encountering a problem using R, you’ll likely to find a solution on the R help mailing list, online tutorials (A very convenient and easy accessible reference is Quick-R), one of the numerous blogs about R (see e.g., R bloggers, Cerebral Mastication, Recology) and the various other sources of information listed on the R website.
Still, it sometimes takes me time to find that little trick I need for this obscure problem I am having. And too often I know I have found the solution before, but can’t remember exactly where. So I started to keep a list with pieces of information I have needed at one point and may need again. For others this is, well, just another list with entry points to a number of very helpful or otherwise useful web pages.
General / various
- Useful-r-snippets
- Two minutes R video tutorials
- R Task views, one of the first places to go if you want to know what packages are available for one of the 29 domains of analysis (included views are e.g, spatial, genetics, graphics, machine learning and bayesian statistics)
- Cheat sheet for prediction and classification models in R
Data handling
- Convert strsplit() output (applied to vector) to a data.frame or see this stack overflow Q&A.
- Split column at delimiter in data frame
- Row names in data frames: beware of 1:nrow
- Subsetting rows selecting on more than one value (and other FQA about how to subset data sets)
- Use a string as input in a function
- Set the numbers of decimals R shows
- Create an integer value for a constant: You can use the function as.integer(). An arguably simpler approach is to qualify your constant with the suffix character ‘L’. For example, to create the integer value 1, we use 1L
- Using R instead of Pivot table in Excel using reshape or reshape2. See also this blog post.
- Frequencies and Crosstabs using table(), xtabs() or CrossTable(). See also this blog
- Convert Contingency Table to Flat File (‘flattened’ contingency table or original raw data frame)
- Concatenate vector with numbers whereby the numbers are separated by a comma: see toString() or paste(c(1:10), collapse=”,”). The former will separate the numbers by a comma followed by space. Using the latter will give you a string with numbers separated by comma only.
- Get the indices of columns in a data frame given their names
- Combining text from data frame in one text string in R
- strptime(): Convert between character representations of time and date into objects of classes
"POSIXlt"and"POSIXct". - Aggregate using multiple functions: use summaryBy() from the doBy package
- Dealing with factors: Rpitfal #3; friggin’ factors
- Sweeping through data in R
- Cumulative Frequency Distribution
- Cumulative Relative Frequency Distribution
- Interrupting R processes in Linux
- Tricks to manage the available memory in an R session
- Increase memory limit used by R: memory.limit(), e.g., memory.limit(size=2500) with size is in MB
- Finding and renaming long file names with R
- To give a name to a data.frame from a character vector of names, use the assign() function
Functions
- Finding the code for ‘hidden’ function in R or check this and this email threat.
- The dput() function gives you an ASCII text representation of an R object, which can be used to recreate the object. Good for e.g., sharing in an example on fora or blog posts. Most useful for simpler objects such as data frames, vectors or matrices
Creating a R package
- Building a package in RStudio is actually very easy
- Building R packages; an introduction
- Creating R Packages (the idiot’s guide)
- Creating R packages: a tutorial
- Tips for R Package Creation
Graphs
- R Graphical Manual
- R Graph Gallery
- Visualizing pairwise comparisons. See also this blog for another example using pairs, this blog for an example of a correlation scatter-plot for ordered categorical vectors and this blog post for scatter plots for large datasets.
- Boxplots, violin plots and bagplots, a quick tutorial in Quick-R
- The Many Uses of Q-Q Plots
- Convex hull graph
- Figures, and their axes.
Coding
- Speeding up R computations: Some surprising ways to speed up your R code
- Speed up your R code using a just-in-time (JIT) compiler
Analysis
