Here is the script (slightly editted) of the demo of R given in lecture on October 17. R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > 7+9 [1] 16 > a <- 8*7 > a [1] 56 > > 7.9 [1] 7.9 > > a<100 [1] TRUE > > as.numeric(a<100) [1] 1 > > 1:3 [1] 1 2 3 > 1:8 [1] 1 2 3 4 5 6 7 8 > c(6,4,9) [1] 6 4 9 > b<-c(6,4,9) > b [1] 6 4 9 > b[2] [1] 4 > > b[2]<-99 > b [1] 6 99 9 > > x <-list(a=9, b=0, c=65) > x $a [1] 9 $b [1] 0 $c [1] 65 > x$b [1] 0 > x$b <- 234 > x $a [1] 9 $b [1] 234 $c [1] 65 > x$b <-TRUE > x $a [1] 9 $b [1] TRUE $c [1] 65 > square <- function (x) X^2 > square function (x) X^2 > square(8) Error in square(8) : Object "X" not found > square <- function (x) x^2 > square(8) [1] 64 > > function <- 9 Error: syntax error > > flip <- function (p) { u <- runif(1); u

flip(0.8) [1] TRUE > flip(0.8) [1] TRUE > flip(0.8) [1] TRUE > flip(0.8) [1] TRUE > flip(0.8) [1] TRUE > flip(0.8) [1] FALSE > flip(0.8) [1] TRUE > u Error: Object "u" not found > # comment > > flip <- function (p) { u <- runif(1); return (u flip(0.5) [1] FALSE > > a [1] 56 > if (a<70) print(99) else print(33) [1] 99 > while (a>50) { print(a); a <- a-1 } [1] 56 [1] 55 [1] 54 [1] 53 [1] 52 [1] 51 > a==56 [1] FALSE > a==50 [1] TRUE > a!=50 [1] FALSE > a>=0 [1] TRUE > a>=0 && a<100 [1] TRUE > > a <- 1 + + 3 > a [1] 4 > a <- 1