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

Subscribe to Benchmarks Online
    

RSS Matters

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:

wpe5.jpg (7432 bytes)
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:
wpeA.jpg (3974 bytes)
An incomplete expression will lead to a second prompt,   "+". You can continue with your expression at the second prompt:
wpeE.jpg (1993 bytes)
If the “+” prompt continues after pressing "Enter", then enter many “)” to get the “>” prompt back again. Then start your expression once again:
wpe14.jpg (5400 bytes)

 

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:

wpe16.jpg (2218 bytes)
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:
wpe17.jpg (2121 bytes)

 

Vectors

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

wpe1D.jpg (6710 bytes)
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:
wpe1F.jpg (3442 bytes)
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:
wpe20.jpg (5352 bytes)

 

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:

wpe21.jpg (17262 bytes)
Objects remain until removed, even if one quits S-Plus:
wpe22.jpg (2644 bytes)

 

Objects as Variables

Objects can be used in expressions:

wpe23.jpg (7498 bytes)

 

Vector Arithmetic

Scalar Functions work on an element-wise basis. It is also possible to perform scalar and vector arithmetic:

wpe24.jpg (3420 bytes)

 

Logical Vectors

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

wpe25.jpg (7838 bytes)

 

Missing Values

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

wpe26.jpg (4620 bytes)

 

Vector Indexing

S-Plus uses brackets, [ ], to select elements of a vector. Negative indices remove elements:

wpe27.jpg (3503 bytes)

wpe28.jpg (2819 bytes)

 

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).

wpe29.jpg (5642 bytes)

 

Replacement

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

wpe2A.jpg (3828 bytes)

 

Next Time

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