Question

Does anyone know a good online resource for example of R code?

The programs do not have to be written for illustrative purposes, I am really just looking for some places where a bunch of R code has been written to give me a sense of the syntax and capabilities of the language?

Edit: I have read the basic documentation on the main site, but was wondering if there was some code samples or even programs that show how R is used by different people.

Was it helpful?

Solution

I just found this question and thought I would add a few resources to it. I really like the Quick-R site:

http://www.statmethods.net/

Muenchen has written a book about using R if you come from SAS or SPSS. Originally it was an 80 page online doc that Springer encouraged him to make a 400+ page book out of. The original short form as well as the book are here:

http://rforsasandspssusers.com/

You've probably already seen these, but worth listing: http://cran.r-project.org/doc/manuals/R-intro.pdf http://cran.r-project.org/doc/contrib/Owen-TheRGuide.pdf http://cran.r-project.org/doc/contrib/Kuhnert+Venables-R_Course_Notes.zip

I don't want to sound like a trite RTFM guy, but the help files generally have great short snips of working code as examples. I'm no R pro so I end up having to deconstruct the examples to understand them. That process, while tedious, is really useful.

Good luck!

EDIT: well I hesitated to be self linking (it feels a bit masturbatory) but here's my own list of R resources with descriptions and comments on each: http://www.cerebralmastication.com/?page_id=62

OTHER TIPS

Why not look at www.r-project.org under documentation and read at least the introduction? The language is sufficiently different from what you're used to that just looking at code samples won't be enough for you to pick it up. (At least, not beyond basic calculator-like functionality.)

If you want to look a bit deeper, you might want to look at CRAN: an online collection of R modules with source code: cran.r-project.org

The Rosetta Code project shows R compared to other languages.

How about CRAN? You've got over a thousand packages of code to choose from.

The simplest way of seeing code, is to

  1. install R
  2. type "help.start()" or look at online documentation, to get names of functions
  3. type the function name at the prompt

This will print the source code right at the prompt, and illustrate all manner of odd and interesting syntax corners.

The Learning R blog has a lot of good examples. Lately, the author has been doing a visualization series, comparing Lattice and ggplot2.

It is hard to google r, because of it being too short a name. Try http://rseek.org/, which provides an r-customized Google search instead. Search on examples, code in repositories, etc.

Some simple examples can be found at Mathesaurus - if you know e.g. Python or Matlab, look at the respective comparison charts to find the R idioms that correspond to your familiar idioms in the other language.

I use the R Graph Gallery. It has been a lot of help on graphing itself. Lots of good examples.

#R on Freenode has also been very useful.

http://had.co.nz/ggplot2/ has a lot of graphics with example code. And you only need one package to create almost every graph you need.

There is also the R Wiki which is slowly growing.

As you probably know, R and S are pretty similar (apart from the cost!).

I use to use both, and I highly recommend S Poetry.

I can also highly recommend the M.J. Crawley book, and the shorter Venables & Ripley one.

here are links to the R project group on Linkedin. I put together this list of links and a lot of people have found it useful (some have also made very useful additions)

Use Google Code Search with command "lang:r" and your keyword(s)

Steve McIntyre at http://www.climateaudit.org/ is a big fan of R and often posts working code.

There is a scripts category, and the Statistics and R lists some other resources

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top