Table of Contents

Introduction to R

Why R ?

dsc2001.jpg Ross Ihaka and Robert Gentleman at DSC 2001

R is a programming language and environment for data analysis developed in nineties by Ross Ihaka and Robert Gentleman from University of Auckland, New Zealand. It is an open-code implementation of language S developed in 1976 by John Chambers and his collaborators at Bell Laboratories. A commercial version of S is known as S-Plus.

In the new millennium many statisticians joined the project that became the main environment for development and publication of new statistical (and other) methods. In June 18, 2017 there were 10852 packages on the CRAN. See also R-Forge, GitHub/Wickham.

The main rival to R is Python with Pandas, and in the future Julia.

Some links

R interpreter

Executing program R the R Console window appears with basic info about R version. It ends with a character >, that informs us that R is ready to receive commands (expressions). We terminate the session using q(), or <Ctrl>Z, or selecting File/Exit, or with a click on X button of the program window.

Examples of simple expressions are mathematical expressions - R can be used as a calculator:

> 1+1
[1] 2
> 3^2 + 4^2
[1] 25
> 3 + 4 * 5
[1] 23
> (3 + 4)*5
[1] 35
> pi
[1] 3.141593
> pi * 2.5^2
[1] 19.63495
> 4*atan(1)
[1] 3.141593
> (1+sqrt(5))/2
[1] 1.618034

For a list and details about available functions see help(Arithmetic), help(Trig), help(complex), help(log), help(Round), help(sqrt), etc.

To store a computed value we use an assignment statement:

> a <- 14
> a
[1] 14
> (7 -> a)
[1] 7
> a
[1] 7
> (a <- a+1)
[1] 8
> b <- c <- a
> b
[1] 8
> c
[1] 8
> d
Error: object "d" not found
> rm(b)
> b
Error: object "b" not found
> (b <- a * (d <- 3))
[1] 24
> b
[1] 24
> d
[1] 3
> B
Error: object "B" not found
> (B <-2009)
[1] 2009

The basic data types in R are: numeric, integer, complex, logical, character, and raw. They can be combined into structured objects using: vector, matrix, array, list, etc.

For testing and converting types we have functions

R is a programming language. About the basic control statements see R-control.



Back to 7ISS Labs