[ top | up ]
Read data from a file
Syntax
read.file(filename, varnames, numeric, nvars, header)
Arguments
filename
|
the file to be read.
|
varnames
|
the names of the variables to be read in, a string vector.
|
numeric
|
a logical vector specifying which of the variables are numeric.
|
nvars
|
the number of variables.
|
header
|
a logical value indicating whether or not there is a header line
in the file giving the variable names.
|
Value
null is returned. This function is executed for its side effects.
The variables varnames are created using data from filename.
Description
If header is specified then the file is scanned and the variable names
are read from the first line of the file (only one line is read).
If nvars is specified and varnames is missing and header
is false then variable names, var1 through varn, are made up.
If numeric is not specified data is assumed to be character.
The file is scanned reading in the data.
The data vectors scanned in are then assigned to the appropriate variable
names.
Examples
# file foo has 30 numbers in it, 10 rows, 3 columns.
read.file("foo",c("age","sex","height"))
# age sex and height are now variables
read.file("foo",nvar=3)
# var1, var2, var3 have been created, each 10 long