Page One Campus Computing News Y2K A-OK? Large Group E-Mail Guidelines J2 on the Academic Mainframe MailBook 2000 on Academic CMS WebCT Frequently Asked Questions (and Answers!) Is Your Student Organization Online? RSS Matters The Network Connection List of the Month WWW@UNT.EDU Short Courses IRC News Staff Activities

 By Rich Herrington, Research and Statistical Support Services

## Exploring S-Plus 5.1 on UNIX (SOL) - Part II

In the August 1999 issue of RSS matters we provided an introduction to using S-Plus on SOL (http://www.unt.edu/benchmarks/archives/1999/august99/rss.htm). In this issue we continue our exploration of S-Plus on SOL.

### Constructing Expressions in S-Plus

To begin our session we must invoke S-Plus after logging onto SOL. Type "Splus5" at the UNIX prompt to start the S-Plus session. You should see the following screen:

S-Plus expressions are typed in at the ">" prompt. S-Plus 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, S-Plus will look for a possibly non-existent 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, x-yvar,  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 S-Plus:

### Objects as Variables

Objects can be used in expressions:

### Vector Arithmetic

Scalar Functions work on an element-wise 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

S-Plus 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 S-Plus!