The read.table() function

To read an entire data frame directly, the external file will normally have a special form.

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
\begin{figure}
\hrule\medskip
\begin{verbatim}
Price Floor Area Rooms Age Cent.h...
 ...6 8.8 no
05 59.75 93.0 900 5 1.9 yes
...\end{verbatim}\medskip\hrule\end{figure}

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
\begin{figure}
\hrule\medskip
\begin{verbatim}
Price Floor Area Rooms Age Cent.h...
 ...0 6 8.8 no
 59.75 93.0 900 5 1.9 yes
...\end{verbatim}\medskip\hrule\end{figure}

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