To follow this handout while running S-PLUS, go to the directory
/afs/andrew/stat/data/S-Tutorials
and copy examples 1 through 6
and the file football.dat
to your home directory. Then go to your home
directory and run S-PLUS.
There are many ways to read data, including scan
and
read.table
. The function scan("filename")
reads a file
as a vector. This is useful if the data file consists of one vector,
or the data have an unorthodox structure that cannot be read any other way.
If the data in the file are laid out neatly in a table, the best way
read them into S-PLUS is with read.table
. This function returns a
data frame (an object which has several columns of data, each of which
represent a different variable). The function read.table
has several different options which allow you to read data from
several different formats.
S-PLUS for Windows can read data from fancier formats, for instance Lotus and Excel files, when you choose ``Import-External Files'' from the menu.
The six example files contain fictitious data regarding the dose
of a pain reliever that a patient took, how much water he or she took it
with, and how much pain relief he or she experienced. The six files have
only minor differences, to demonstrate the different formats from which
read.table
can read data.