Reading External Data


One uses the read.table(...) routine to read in external data that is in a tabular format. The read.table(...) routine returns a data.frame object that contains the data. A data.frame is a two dimensional data structure that can contain row and column names as well as numeric data.

Original documentation : read.table, data.frame

Samples

# Given a file testData.dat with the entries
3.0 3.0
4.0 4.0
5.0 7.0

# read the data then print it out

  testData <- read.table('testData.dat');
  testData
    V1 V2
  1  3  3
  2  4  4
  3  5  7

# Given a file testData2.dat with the entries
x y
3.0 2.0
4.0 3.0
5.0 4.0
# read the data, then print and plot the data

  testData2 <- read.table('testData2.dat',header=TRUE);
  testData2

    x y
  1 3 2
  2 4 3
  3 5 4

  plot(testData2[['x']],testData2[['y']],type='l');


UCLA Mathematics Department ©2000