z
q()
### Use this to quit
Scalars are treated by S-plus as vectors of length 1. That is why they print with a
leading “[1]” indicating that we are at the first element of a vector.
Vectors can be created using the
c()
command.
c()
stands for concatenate. Square
brackets are used to get subsets of a vector. The colon is used for sequences. Start up R
again then do this:
x = 1:5
### the vector (1,2,3,4,5)
print(x)
x = seq(1,5,length=5)
### same thing
print(x)
x = seq(0,10,length=101) ### 0.0, 0.1, ..., 10.0
print(x)
x = 1:5
x[1] = 17
print(x)
x[1] = 1
x[3:5] = 0
print(x)
w = x[-3]
### everything except the third element of x
print(w)
y = c(1,5,2,4,7)
y
y[2]
y[-3]
y[c(1,4,5)]
i = (1:3)
z = c(9,10,11)
y[i] = z
print(y)
y = y^2
print(y)
y = 1:10
y = log(y)
y
y = exp(y)
y
x = c(5,4,3,2,1,5,4,3,2,1)
z = x + y
z
### R carries out operations on
2