To read an entire data frame directly, the external file will normally have
a special form.
- The first line of the file should have a name for each
variable in the data frame.
- Each additional line of the file has its first item a row
label and the values for each variable.
If the file has one fewer item in its first line than in its second, this
arrangement is presumed to be in force. So the first few lines of a file
to be read as a data frame might look as in Figure
.
Figure:
Input file form with names and row labels
 |
By default numeric items (except row labels) are read as numeric variables
and non-numeric variables, such as Cent.heat in the example, as
factors. This can be changed if necessary.
The function read.table() can then be used to read the data
frame directly
HousePrice <- read.table("houses.data")
Often you will want to omit including the row labels directly and use the
default labels. In this case the file may omit the row label column as in
Figure
.
Figure:
Input file form without row labels
 |
The data frame may then be read as
HousePrice <- read.table("houses.data", header=T)
where the heading=T option specifies that the first line is a line of
headings, and hence, by implication from the form of the file, that no
explicit row labels are given.
Jeff Banfield
2/13/1998