Exploring
SPlus 5.1 on UNIX (SOL)  Part II
In the August 1999 issue of RSS matters we
provided an introduction to using SPlus on SOL (http://www.unt.edu/benchmarks/archives/1999/august99/rss.htm).
In this issue we continue our exploration of
SPlus on SOL.
Constructing Expressions in
SPlus
To begin our session we must invoke SPlus
after logging onto SOL. Type "Splus5"
at the UNIX prompt to start the SPlus session.
You should see the following screen:


SPlus expressions are typed in
at the ">" prompt. SPlus will print
out the results of the evaluation once the
"Enter" key is pressed: 

An incomplete expression will
lead to a second prompt,
"+". You can continue with your
expression at the second prompt: 

If the “+” prompt
continues after pressing "Enter", then
enter many “)” to get the
“>” prompt back again. Then
start your expression once again: 

Scalars and Assignments
The assignment operator is the sequence of
characters, "<" (less than) and
"" (hyphen). Assigning the variable
“weight” the value of 190 we use
the following:


Character values are inserted in
quotes. If the quotes are omitted, SPlus
will look for a possibly nonexistent data object
called "Jim" to assign to the variable
"person". The result is not
printed until you enter the object name: 

Vectors
The function "rnorm( )",
returns a vector of random deviates from
the normal distribution The "[n]" on
the left shows where the row starts:


A single number is a vector of
length 1. We can make vectors using the
concatenation function, "c( )".
Then we can assign the integers 1,2,3 to the
vector x: 

We can create a vector of names.
Also we can create a vector of sequential
integers using the function, "a:b",
where a is the starting integer and b is the
ending integer: 

Object Names
Object names may contain letters,
"abcDEF", or numbers,
"0123456789", or a dot,
".". Examples of valid names:
height, weight, x.var, .yvar,
x.y.var, or x110. Objects names cannot
use an underscore, a hyphen, begin with a number,
or use reserved symbols. Examples of invalid
object names: _xvar, y_var, xyvar,
120xvar, T, F, or NA.

Handling Objects
We can list out all of the objects in our
workspace:


Objects remain until removed,
even if one quits SPlus: 

Objects as Variables
Objects can be used in expressions:


Vector Arithmetic
Scalar Functions work on an elementwise
basis. It is also possible to perform scalar and
vector arithmetic:


Logical Vectors
Expressions with relational operators return
logical vectors, "T" is
True, "F" is False:


Missing Values
A missing value is represented by
"NA". Operations on NA return NA. The
function is.na( ) checks for missing values:


Vector Indexing
SPlus uses brackets, [ ], to select elements
of a vector. Negative indices remove elements:


Logical Indices
A logical index selects elements. Symbols for
the logical operators are: "<"
(less than), ">" (greater
than), "<=" (less than or
equal to), ">=" (greater than
or equal to), " = =" (equal to),
"!" (negation operator),
"!=" (not equal to).


Replacement
You can use [ ] on the left hand side of an
assignment, "<" :


Next Time

Next time we will cover
matrices, arrays, and lists, among other topics.
Good luck with SPlus! 