Skip to content

Instantly share code, notes, and snippets.

@xquery
Created March 3, 2012 19:17
Show Gist options
  • Select an option

  • Save xquery/1967597 to your computer and use it in GitHub Desktop.

Select an option

Save xquery/1967597 to your computer and use it in GitHub Desktop.
Learning R - some basics
R is an object-oriented language with every object having a type (and being a member of a class)
*** What is R written in ?
R itself, c and fortran (autoconf, shell script)
http://blog.revolutionanalytics.com/2011/08/what-language-is-r-written-in.html
though some R packages are in c++, Perl, etc
*** basics
> R
starts everything
>q()
quits
>help()
will give you some help
***** basic math funcs
>exp(1)
2.71828182845905
***** range of numbers
> x <- 1:3
| 1 |
| 2 |
| 3 |
***** define functions
> x <- 1:5
> square <- function(x) {
> x^2
> }
> square(x)
| 1 |
| 4 |
| 9 |
| 16 |
| 25 |
***** easy to define vector (arrays) and get specific member
> b <- c(1,2,3,4,5,4343,7,8,9,10,11,12)
> b[6]
4343
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment