The essential functions of R cheatsheet
80% of everything you need on two pages

👇 Download link is at the bottom of the post 👇
Something that I quickly came to learn as an ecologist using R is that out of the hundreds (possibly thousands?) of functions available in R, only a handful were those that I used frequently throughout my code.
I’m also learning to speak Spanish right now, and I’ve found that for learning a new language it is a good idea to start by focusing on the most common words, since only those few words account for a significant proportion of everything you’ll ever need to say.
Anyone familiar with Tim Ferriss probably knows about the 80-20 rule (Pareto’s principle) that he’s made popular throughout his books and podcasts. The rule simply states that 80% of results come from 20% of the work.
To apply that to learning a language, learning only a small proportion of words (20%) will allow you to say a large proportion (80%) what you’d ever need to say. Now, these percentages might not be exactly the same for every application, but hopefully you get the point.
Now back to R! So, that’s what I did with all the functions I use in R. I found the “20%” of functions that I ever used in ecology that gave me the most results. In other words, if you learn these functions (51 functions to be exact), you will be well on your way to do almost anything you need to do with your data. And if there’s something missing, that will be easy to learn when you need it.
So here is my version 1.0 of a cheat sheet on the essential functions of R (for ecology). Please enjoy and share! Notice a typo? Let me know in the comments below.
Also be sure to check out R-bloggers for other great tutorials on learning R
Thanks
Thanks a lot!
thank you!
Thank you :)
Thank you very much for your effort!
Thank you
Thx
thanks!
Thank you
Thank you!
thanks
Thanks
Thanks a Lot!
Thanks from Poland!
Thanks a lot
Thanks a lot from Lebanon
Thanks a lot!
For help with your Spanish: http://mexicobob.blogspot.com/2009/07/learning-spanish-corn-flakes-method.html
Thank you very much, this is helping me to work on my data! -- From Indonesia
Watch out with setwd() or Jenny Bryan will burn your computer down 😜 https://www.tidyverse.org/blog/2017/12/workflow-vs-script/
hahaha yeah... maybe I decided to keep it in there just to make the point. Thanks for sharing that!
i always just use ? instead of help(). Saves a bit of typing! Maybe worth mentioning gsub with grepl lastly, a vote for %in% good stuff!
Great suggestions! I'll keep these in mind for the next version. Thanks!
I wonder if it'd be useful to write the non-base functions as pkgname::fn() rather than "fn() uses pkgname"? For example, lubridate::ymd(), dplyr:: mutate(), etc. It's more in keeping with the recommended style when developing packages and is safer to use in scripts, especially for simple function names that might be used in more than one package.
And thanks for creating this! It'll be very useful for teaching.
Thanks for the suggestion. Yeah, that makes sense. For now the goal was to keep things simple, but perhaps I'll make a cheatsheet soon with the best practices (such as what you recommend here).
Hi, great summary! But if you're recommending some tidyverse functions (
tibble
,left_join
,select
,filter
,mutate
), why not also recommend the infinitely easier to useread_csv
andwrite_csv
fromreadr
? I can see why you'd stick to base plotting in favour of ggplot2 for such an overview, but those two functions are so much more beginner friendly IMO that I would definitely include them (when TA'ing, most issues were with people using;
-separated files etc.)Hi Ilja, and thank you so much for that suggestion. You are probably totally right. The reason I stuck to read. and write.csv for now is because those functions are always taught so commonly at the beginning of most courses that I didn't want to make it that much more confusing for someone just starting out (i.e., by having them learn yet another loading data function). That said, you make a very good point so I'll definitely consider that for the next version of this cheatsheet. Definitely a work in progress!
Cool! Yeah, it's a hard balance between keeping it simple and keeping it powerful. I loved these two contrasting articles on the subject: why NOT to teach tidyverse to beginners (keep it simple): https://github.com/matloff/TidyverseSkeptic DO teach tidyverse to beginners (show powerful examples): http://varianceexplained.org/r/teach-tidyverse/
Oh that's really cool! Thanks for sharing those articles. I'll have a read.