Introduction

Reasons to use R:

Invocation:

Simple invocation on Unix command line: R

Useful command line options (see man R for more):

R --no-save --quiet

Command line interface:

>  2+3
[1] 5

Setting options with R session:

> options(prompt="  ")
  10^5
[1] 1e+05
  options(scipen=100)
  10^5
[1] 100000

Put frequently used options in ~/.Rprofile

Assignment:

  mypi <- 3.14
> mypi
[1] 3.14
  pi
[1] 3.141593

Sequences:

  1:10
 [1]  1  2  3  4  5  6  7  8  9 10

Matrices:

  matrix(1:10, nrow=2, byrow=T)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10
  matrix(1:10, nrow=2)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10
  rbind(1:3, 4:6, 7:9)
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
  m <- rbind(1:3, 4:6, 7:9)
  m[2,]
[1] 4 5 6
  m[,3]
[1] 3 6 9

Vectors:

  y <- c(20, 17, 24, 19, 24, 24, 21, 29, 13, 9)
  y
[1] 20 17 24 19 24 24 21 29 13  9
  y[c(2,3,5)]
[1] 17 24 24
  y[1:5]
[1] 20 17 24 19 24
  mean(y)
[1] 20
  sd(y)
[1] 5.868939