Princeton University Library Princeton University Library

Search DSS

Finding Data Analyzing Data Citing data

About Us

DSS lab consultation schedule
Sep 1-Oct 16By Zoom appt. here
Oct 19-Dec 4Virtual Zoom Walk-ins
Dec 7-Jan 31By Zoom appt. here
Feb 1-April 30Virtual Zoom Walk-ins
May 3-Aug 31By appt. here
For quick questions email
*No appts. necessary during walk-in hrs.
Note: the DSS lab is open as long as Firestone is open, no appointments necessary to use the lab computers for your own analysis.

Follow DssData on Twitter
See DSS on Facebook

Home Online help Statistical packages S-Plus S-Plus Syntax

S-Plus Syntax

The Basics

S-Plus has a very consistent language syntax and many of the basic commands mirror basic unix commands:

Basic Splus Commands
ls() list files in directory
rm(object) remove object from current directory
q() quit Splus
?command find help on any command
!unix command perform any unix command from within Splus

Note that all commands in Splus include parentheses (). Sometimes, you'll include things in the parentheses, as you do when you type rm(object). If you're interested in learning a lot more about programming, try typing a function without the parantheses. S-Plus will output the actual function, which may look long and messy.


When you perform a command in S-Plus it does not automatically become an object. Instead, you must "assign" the output to an object. For example, when you read in data, as we will shortly, you need to tell S-Plus to store this data in a particular object. You do this by assigning it to an objectname. Here's an example:

  • givemeafive <- 5

Try typing this now. Then type givemeafive. You should see a five on your screen. The little arrow (<-) means assign 5 to the object givemeafive. Now, lets see what happens when you forget to assign output to a particular object. Try typing:

  • rnorm(10000)

Wow, that was a lot of output which you probably did not want to go on the screen.

One last thing: <- can be abbreviated as _ (underscore). That makes it easier to type. Now were almost done with the basics.

Types of objects

As was mentioned earlier, Splus is object oriented. Everything you do in Splus will involve creating objects. This includes both data sets and the linear models you create. Here are three types of objects ypou need to know about:

a simple string of either numeric, textual, or logical characters with any number of observations. There are several types of vectors which correspond to several types of data: numeric, character, and logical (True/False) are the most useful and regularly used.
data frame
a multiple row and column object which contains data of any sort. Data frames are useful in that each column is recognized as a distinct object of its own when used inside a statistical function or when using the attach() function. Note that a data frame is the only type of object which you can attach.
output objects come from functions run by S-Plus, such as a linear model (regression) command. One nice feature of S-Plus is that you can access different parts of output easily, as you shall see shortly.
This page last updated on: