Super minor nitpick:
R Studio is the development environment.
R
is the language.
Presumably you want to become well versed in the latter rather than the former. It's an easy mistake to make though, since the two are so intertwined for most people as to become almost indistinguishable.
More to your point though:
Before learning anything, it's a good idea to ask yourself why you want to learn it, and what you hope to be able to do with it. Now, you mentioned two things,
Hypothesis testing.
Graphing 4 variables.
Both of these are relatively simple, and if you have even the most rudimentary understanding of R
, you could learn to do in a couple of minutes.
So, my question to you would be, in using R
is your goal to get quick, simple answers to straightforward questions OR are you ultimately looking to be able to do much more complicated tasks? This isn't a judgemental question, not everyone needs to aspire to become an R
god, just needing something quick and dirty is perfectly okay.
If the things you mentioned are more or less the extent of your needs, I'd suggest just googling what you need to do at the time and pick up what you need, more or less, through osmosis.
However, if you have designs on being able to do amazingly complicated things, if you want to push R
to its fullest, you'll need a more structured approach.
One thing you absolutely must understand is R
is a package based language. What this means for you is that beyond the numerous ways you can do any task in any language, people have written countless* packages which contain all sorts of handy functions to do just about anything you could conceivably want to do.
>* Okay, it's not really countless, there are (as of this writing 12,620 packages on CRAN and 1,560 additional packages on bioconductor. There are bunches more of unofficial ones scattered about GitHub and others privately maintained, but you get the point, there's lots of them.
So, for anything you want to do, you can approach it in one of two, very broad, ways:
Base R
.
Using packages.
When you are starting out, I think it's very important to get a good handle on Base R
.
I would start out with basically any introductory R
book. Search on Amazon and just find one you like.
Personally, I can recommend Using R for Introductory Statistics by John Verzani. It isn't for everyone, but if you're truly a beginner to both R
and statistics more generally, it's a good reference text.
After that it's, up to you. Where you want to take it. For me, the pantheon of R
gods* I would pay tribute to are these four:
The god of tidiness - Hadley Wickham GitHub/u/hadley
The god of speed - Dirk Eddelbuettel GitHub
The god of art - Winston Chang GitHub
>*I'm sure every single person on that list would balk at being called a "god," but they'd be lying.
It's no mistake that 3/4 of them work for R Studio.
Hadley must be a complete neat-freak because he's the driving force behind the <code>tidyverse</code>,
>The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
Once you branch out of base R
, the tidyverse
should be your first destination. It's not quite a new language unto itself, more like a very sophisticated dialect of the language you already know. Once you can speak "tidy," you can still communicate with the "base" speaking plebs, you just won't be able to imagine every wanting to.*
>* this is not exactly true, and might come across as gross and elitist, but the tidy
paradigm really is substantially better. If you were designing a completely new language to do statistical competing, from scratch, today, the language would probably feel a lot like the tidyverse
.
Anyway, any book by Hadley Wickham is gold, and they're all available online for free. But R for Data Science is a good first step into a larger world.
I imagine Dirk is not a patient man. He's very active on forums, basically every meaningful response on stackexchange for an Rcpp related question is his (or his collaborator, lesser-god Romain Francois), but sometimes his responses can seem a little... terse?
Now, R
is notoriously slow. It's much maligned for this, usually fairly, sometimes not.
Much of the perceived slowness can be mitigated in base R
by learning the suite of apply
functions which are vectorized. That is they take a multivalued variable (a vector, matrix, or list) and they apply the same function to each element. Its typically much, much faster than using a for-loop. However, you can't always get away from needing a for-loop, and sometimes your loop will need to run thousands (or millions) of times. That's where the Rcpp
package which Dirk maintains comes into play.
It is an interface between R
and C++
, there's not much to say about the package itself. You'll need to learn at least some rudimentary C++
to make use of it, but simply breaking out a computationally intensive for-loop into an Rcpp
function can yield a huge improvement in run times. 10x-100x (or more) depending on how well (or poorly) optimized your R
and C++
code is. There's some weirdness involved (like you can't call an Rcpp
function in a parallel apply function (separate package) unless your Rcpp
function is loaded as part of a package, so for maximum benefit you'll need to learn how to write your own packages - praise be to Hadley).
Rcpp
includes some semantic "sugar" which allows you to write some things in C++
more like you would in R
, but that's yet a third thing to learn.
Also Rcpp
, much like the tidyverse
is more an ecosystem of interconnected packages than a single package.
Base R
plots are ugly as sin. They just are, no one should use them ever, for any reason.*
>*Exaggeration.
That said, Winston's* ggplot2
is a revelation and a revolution in how graphics are created and presented.
>* Yes, technically ggplot2
is also Hadley's and is part of the tidyverse
, but Winston literally wrote the book on it. Okay, okay, Hadley technically created the package and has written books about it, I just find Chang's book more fitting to my needs.
The "gg" in ggplot2
stands for "grammer of graphics", a common structure for describing the components of a visualization in a concise way.
Learning ggplot2
will take you a long way toward being able to make beautiful graphical visualizations.
After you've learned all of the above. You can wrangle your messy data into something tidy and manageable, you can work on it cleanly and power through massive computations, and you can create stunning images from your data, it all means nothing if you're the only one who sees it.
This is where Yihui shines. He is the maintainer for the knitr
package, and the author of Dynamic Documents with R and knitr. This will allow you to turn all of your work into PDFs or web pages to share with the world.
It's super easy to get started with, much more complicated to master, but definitely worth it.
To use it effectively, you'll need to learn rmarkdown
also by Yihui. You'll also want to start dabbling with <code>LaTeX</code> (if your not proficient already) and to truly bend documents to your whim you'll need to learn to tinker with <code>YAML</code>.
It's a lot to master. Few ever will. Not everyone will agree on everything I've said, but I think the park to true mastery looks something like that.
Best of luck!
Are you learning R or learning statistics? R is not a general-purpose language like Java or Python. It does one thing and one thing well: statistics. Learning it without understanding stats would be very difficult. That said, some of its syntax is very odd indeed.
You might find Kaggle helpful. There are tons of R workbooks you can look at to see how things are done.
I know you are asking for on-line resources, but you might find Using R for Introductory Statistics.