S-PLUS operates on named data structures. The simplest such structure
is the vector, which is a single entity consisting of an ordered
collection of numbers. To set up a vector named x, say, consisting
of five numbers, namely
,
,
,
and
, use the S-PLUS
command
x <- c(10.4, 5.6, 3.1, 6.4, 21.7)
This is an assignment statement using the function c() which in this context can take an arbitrary number of vector
arguments and whose value is a vector got by concatenating its
arguments end to end.
A number occurring by itself in an expression is taken as a vector of length one.
Notice that the assignment operator is not the usual = operator, which is reserved for another purpose. It consists of the two characters < (`less than') and - (`minus') occurring strictly side-by-side and it `points' to the structure receiving the value of the expression. Assignments can also be made in the other direction, using the obvious change in the assignment operator. So the same assignment could be made using
c(10.4, 5.6, 3.1, 6.4, 21.7) -> x
If an expression is used as a complete command, the value is printed and lost. So now if we were to use the command
1/x
the reciprocals of the five values would be printed at the terminal (and the value of x, of course, unchanged).
The further assignment
y <- c(x, 0, x)
would create a vector y with
entries consisting of two
copies of x with a zero in the middle place.