background preloader

Learning and Teaching R

Facebook Twitter

Cheatsheets - RStudio. The cheat sheets below make it easy to learn about and use some of our favorite packages.

Cheatsheets - RStudio

From time to time, we will add new cheat sheets to the gallery. If you’d like us to drop you an email when we do, let us know by clicking the button to the right. Data Visualization Cheat Sheet The ggplot2 package lets you make beautiful and customizable plots of your data. It implements the grammar of graphics, an easy to use system for building plots. Package Development Cheat Sheet. DIY – cheat sheets. I found recently, that in addition to a great list of cheatsheets designed by RStudio, one can also download a template for new cheatsheets from RStudio Cheat Sheets webpage.

DIY – cheat sheets

With this template you can design your own cheatsheet, and submit it to the collection of Contributed Cheatsheets (Garrett Grolemund will help to improve the submission if needed). Working on a new cheatsheet is pretty enjoying. You need to squeeze selected important stuff into a quite small surface like one or two pages. Lots of fun. R-project Search Engine. Search for "natural" usage of a function across all CRAN packages. Stack Overflow. The Guerilla Guide to R. Update: Okay.

The Guerilla Guide to R

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: About: Stack Overflow is awesome. R Wiki - Tips. R Cheat Sheets. R Cheat Sheet. One Page R: A Survival Guide to Data Science with R. R spells for data wizards. I’ve never come up with a good way for learning/teaching the cool parts of R.

R spells for data wizards

I feel like that’s sort of how R is; there’s an awesome way to do everything, but it’s all very specific and kind of hacky. I thought of some magic incantations that you might not find in introductory R books/documentation/classes and wrote about them below. When loading a CSV, don’t convert strings to factors. read.csv('', stringsAsFactors = F) When writing a CSV, don’t add the rownames. write.csv(iris, file = 'iris.csv', row.names = F) Indexing It’s easy to miss a level of indexing, especially with lists.

DataCamp. Useful tutorials. There are some tools that I use reg­u­larly, and I would like my research stu­dents and post-​​docs to learn them too.

Useful tutorials

Here are some great online tuto­ri­als that might help. ggplot tuto­r­ial from Win­ston ChangWrit­ing an R pack­age from Karl BromanRmark­down from RStudioShiny from RStudiogit/​github guide from Karl Bromanmin­i­mal make tuto­r­ial from Karl Broman. Twotorials by anthony damico. Google Dev R Video Lectures. I got this Google Developers R Programming Video Lectures from Stephen's blog - Getting Genetics Done.

Google Dev R Video Lectures

Very useful R tutorial for beginner! Short and efficient. Learning R. Complete beginner: read the 12-page A (very) short introduction to R by Torfs & Brauer.

Learning R

Beginner / intermediate: read R for Data Science, by Hadley Wickham. It teaches both fundamental data science concepts and the most modern way of using R (with the tidyr, dplyr, purr and ggplot2 packages). The book should be published in late 2016, but most of the first chapters are already freely available online in draft form. Advanced: read Advanced R, by Hadley Wickham. It is very accessible, and will provide you with an in-depth understanding of the R language. Short courses: Beginner: DataCamp offers a popular, free introductory tutorial, which they say takes 4 hours to complete. Intermediate: The University of Cambridge Bioinformatics Training Facility runs a one-day course on dplyr and ggplot2 packages (the slides are available for free).

DataScience+ Learn R programming for data science. Date Formats in R. Importing Dates Dates can be imported from character, numeric, POSIXlt, and POSIXct formats using the as.Date function from the base package.

Date Formats in R

If your data were exported from Excel, they will possibly be in numeric format. Otherwise, they will most likely be stored in character format. Importing Dates from Character Format If your dates are stored as characters, you simply need to provide as.Date with your vector of dates and the format they are currently stored in. For example, "05/27/84" is in the format %m/%d/%y, while "May 27 1984" is in the format %B %d %Y. Do more with dates and times in R with lubridate 1.1.0.

This is a guest post by Garrett Grolemund (mentored by Hadley Wickham) Lubridate is an R package that makes it easier to work with dates and times.

Do more with dates and times in R with lubridate 1.1.0

The newest release of lubridate (v 1.1.0) comes with even more tools and some significant changes over past versions. Below is a concise tour of some of the things lubridate can do for you. R-gotchas. A guide to tools for collaboration with R. This a brief guide to using R in collaborative, social ways.

A guide to tools for collaboration with R

R is a powerful open-source programming language for data analysis, statistics, and visualization, but much of its power derives from a large, engaged community of users. This is an introduction to tools for engaging the community to improve your R code and collaborate with others. (Am I missing anything? Let me know in the comments and I’ll update this guide.) Topics Asking questions via e-mail, listservs and bulletin boards. Rdocumentation. How do I open R help about a symbol or punctuation mark like ( parenthesis or [ bracket? Top 10 tips to get started with R. In-depth intro to machine learning in 15 hours of expert videos. In January 2014, Stanford University professors Trevor Hastie and Rob Tibshirani (authors of the legendary Elements of Statistical Learning textbook) taught an online course based on their newest textbook, An Introduction to Statistical Learning with Applications in R (ISLR).

I found it to be an excellent course in statistical learning (also known as "machine learning"), largely due to the high quality of both the textbook and the video lectures. And as an R user, it was extremely helpful that they included R code to demonstrate most of the techniques described in the book. (Update: The course will be offered again in January 2016!)

If you are new to machine learning (and even if you are not an R user), I highly recommend reading ISLR from cover-to-cover to gain both a theoretical and practical understanding of many important methods for regression and classification. It is available as a free PDF download from the authors' website. P.S. StatsTeachR. RTutor Package. When is a zero not a zero? > j <- 0 > while (j < 1) j<-j+0.1 > j [1] 1.1 # shouldn't this end with j equal to 1? What's going on? The short answer is that R, like pretty much every other numerical software in existence, uses floating point arithmetic to do its calculations. The basic principle is this: computers don't store numbers (except smallish integers and some fractions) exactly. The principle is the same for floating point numbers: the main difference is that the underlying representation is binary, not decimal.

> j <- 0.1. Vectorization in R: Why? Here are my notes from a recent talk I gave on vectorization at a Davis R Users’ Group meeting. Thanks to Vince Buffalo, John Myles White, and Hadley Wickham for their input as I was preparing this. Feedback welcome! Beginning R users are often told to “vectorize” their code. R Tutorial App. 21 R navigation tools. Navigation gets you from where you are to where you want to be. Speaking of navigation, you can jump to selected sections of this post: Navigation; R-bloggers; Task views;; sos package; ?? Creating your personal, portable R code library with GitHub. As I discussed in a previous post, I have a few helper functions I’ve created that I commonly use in my work. Until recently, I manually included these functions at the start of my R scripts by either the tried and true copy-and-paste method, or by extracting them from a local file with the <code>source()</code> function.

The former approach has the benefit of keeping the helper code inextricably attached to the main script, but it adds a good bit of code to wade through. The latter approach keeps the code cleaner, but requires that whoever is running the code always has access to the sourced file and that it is always in the same relative path – and that makes sharing or moving code more difficult. The start of a recent project requiring me to share my helper function library prompted me to find a better solution. The process is very straightforward. Customize .Rprofile and Keep Your Workspace Clean. How do I install an R package from source. Robin Lovelace - Consistent naming conventions in R. Designing projects - Nice R Code. The scientific process is naturally incremental, and many projects start life as random notes, some code, then a manuscript, and eventually everything is a bit mixed together.

Writing Better Statistical Programs in R. Guide to Speeding Up R Code. SummaryRprof {utils} Improved R Profiling Summaries. Bricks not monoliths. Chapter 32 of Tao Te Programming advises you to make bricks instead of monoliths. Here is an example. The example is written with the syntax of R and is a data analysis, but the principle is valid no matter what language you use or what your task is. Monolith. 3 dots construct in R. Lexical scope and function closures in R. Introduction. Specifying Variables in R. Rules for Naming Objects in R. Memory usage · Advanced R. PITFALL: Did you really mean to use matrix(nrow, ncol)? 5 Reasons to Teach Elementary Stats With R: #3. Random Data Sets Quickly. How do you you determine the namespace of a function? Creating an R course on DataCamp. Creating a course on DataCamp.

UseR! talk on teaching R. How to ask for R help. How to make a great R reproducible example. Minimal reproducible examples. Style - Hadley. StyleO. R for MATLAB users. Translating between R and SQL: the basics. TranslateR your SPSS® script automatically to R. Blue Sky Statistics.