The Guerilla Guide to R

[This article was first published on Optinalysis, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Update: Okay. I’ve uploaded a new template and things seem to be fine now.

Update: I am aware the table of contents is not being displayed in bullet form as I intended. The web template I’m using seems to be buggy. It also seems to think this page is in Indonesian…Working on it!

Table of Contents:
  1. Reading/Writing Files
    1. How to write lines of text into a file
    2. Trimming a huge (3.5GB) csv file to read into R
    3. Quickly reading large dataframes into R
    4. How can I tell if my R dataset is going to be too large?
    5. Standard logging library for R 
  2. Dataframes
    1. How do you write a CSV in R with matrix names dimnames(M) intact?
    2. How to join dataframes in R (inner, outer, left, right)?
    3. Dropping Columns in Dataframes 
    4. Dropping factor levels in a subsetted dataframe
    5. Remove rows with NA in your dataframe 
    6. Creating an R dataframe row by row 
    7. Fastest way to merge/join dataframes
  3. Lists and Vectors
    1. How to correctly use lists in R? 
    2. Levels – what sorcery is this? 
    3. R function for testing if a vector contains a given element?
    4. Converting lists to dataframe 
    5. In R, what is the difference between [] and [[]] notations accessing the elements of a list 
    6. How to convert a factor to an integer/numeric without a loss of information 
    7. How to access the last value of a vector 
    8. Removing an element from a list 
    9. Extracting the last n characters from a string 
  4. Exceptions and Gotchas
    1. What is the biggest R gotcha you’ve run across?
    2. Exception handling in R
    3. Reading commandline parameters from an R script
    4. Assignment operators in R: ‘=’ vs ‘<- a=""> 
    5. Why is not (explicitly) calling return faster or better, and thus preferable? 
    6. Why does TRUE == “TRUE” in R?
    7. What is the difference between ‘1L’ and ‘1’?  
    8. Why does the number 1e99999 (31 9’s) cause problems? 
    9. Examples of the perils of globals in R and Stata 
    10. How to count TRUE values in a logical vector 
  5. Sorting
    1. Letter “y” comes after “i” when sorting?
    2. How to sort a dataframe by column(s) in R?
    3. Fastest way to find the second (or third) highest/lowest value in a vector or column 
  6. Plotting
    1. Plotting 2 graphs in the same plot
    2. How to plot 2 histograms together in R
    3. Histogram with a logarithmic scale 
    4. The most underutilized visualization
    5. Rotating and spacing axis labels in ggplot2 
    6. Shading a kernal density plot between 2 points
    7. Choosing between qplot() and ggplot() in ggplot2 
    8. Intelligent point label placement in R 
    9. Plotting a correlation matrix 
    10. Plotting a 3D surface plot with contour map overlay, using R 
    11. Side-by-side plots using ggplot2 
    12. Ggplot2 cheat sheet 
    13. Plot a human body in 2D 
    14. Plotting 2 variables as lines using ggplot2 
    15. Getting rid of axis values in an R plot 
  7. Grouping Functions and Speed
    1. R grouping functions: sapply vs lapply vs apply vs tapply vs etc. 
    2. Why is ‘[‘ better than the subset function?
    3. Confused by …() 
    4. Speeding up “group by” functions
    5. Options for caching/memoization/hashing in R 
  8. Random
    1. Making XKCD style plots in R 
    2. Developing geographic thematic maps with R
    3. What can Matlab do that R cannot do?
    4. Where to learn C code to speed up your R functions
    5. How to organize large R programs
    6. The difference between library() and require() 
    7. Unloading a package without restarting R
    8. What is the difference between R.exe, Rterm.exe, Rscript.exe, and Rcmd.exe?
    9. What is your preferred style for naming variables in R? 
    10. In R, what exactly is the problem with having objects with the same base name as functions?  
    11. Easter eggs in R 
    12. Drawing an excellent cow  
    13. Display a time clock on the R commandline 
    14. What are slots?  
  9. Case Studies
    1. How to determine the position of the sun at a given time of day, latitude and longitude 
    2. Implementing Model-View-Control (MVC) in R
    3. Scraping html tables into R dataframes 
    4. R + ggplot: time series with events 
    5. Speed up loop operation in R
    6. How to scrape the web for the list of R release dates


Stack Overflow is awesome. Some of the worlds most brilliant programmers frequent the website and answer tough questions. Wouldn’t that make it a great place to learn from? Yeah, I think so too.

This is why I’ve collated, The Guerilla Cookbook for R. It’s basically a number of Stack Overflow links organized and ordered in a way to help R programmers learn their way to the next level. If you are proficient in R, I hope these resources will help you get closer to being amazing. If you are just getting started with R, I’d suggest adding this page to your bookmarks and returning when you are familiar with the basics of R programming.

The cool thing is, this “book” essentially writes itself since most of the experts (and peer-reviewers) are answering the questions. Most of the questions are “real-world” and are asked by novice or intermediate programmers. We can easily add/remove/reorganize the contents as necessary.

How Was The Content Selected?:

I personally searched through Stack Overflow to find my favorite questions and shared them here. 

The table of contents will have to be updated/reorganized over time as links are added and removed. But use whatever you can for now!

To leave a comment for the author, please follow the link and comment on their blog: Optinalysis. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)