Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample Code for R? [closed]

Tags:

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.

like image 785
kaybenleroll Avatar asked Sep 24 '08 13:09

kaybenleroll


People also ask

How do I end code in R?

In the terminal, the “normal” way is Control + C – the “cancel” key combination. In the graphical R application and in RStudio, it's Escape .

What is a closure R?

A closure in R is an object that contains functions bound to the environment the closure was created in. These functions maintain access to the scope in which they were defined, allowing for powerful design patterns that are difficult with the standard S3/S4 approach to objects in R.

Does R have closures?

Closures are used for creating functions within a function in the R environment. These are useful when the functions are changing/ repeating in the code with the same dataset.

What does '$' mean in R?

Generally speaking, the $ operator is used to extract or subset a specific part of a data object in R. For instance, this can be a data frame object or a list. In this example, I'll explain how to extract the values in a data frame columns using the $ operator.


2 Answers

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

like image 141
zvrba Avatar answered Dec 13 '22 11:12

zvrba


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

like image 42
JD Long Avatar answered Dec 13 '22 11:12

JD Long