Next: readdata()
Up: MacAnova Help File
Previous: read()
Contents
Usage:
readcols(FileName,name1,name2,...,namek[,keyword phrases]). FileName a
quoted string or CHARACTER scalar, name1, ... quoted or unquoted
variable names. FileName can also be CONSOLE or have the form
string:charVal where charVal is CLIPBOARD or other CHARACTER scalar or
vector. Keyword phrases may 'realorchar:T' or any vecread() keyword
phrases except startline:M
readcols(FileName,vector("name1",...,"namek")[,keyword phrases])
readcols(FileName[,keyword phrases]), the first line of the file
containing names.
|
Keywords:
input, files
Usage
readcols(FileName,name1,name2,...,namek) uses vecread() to read
numerical data from file FileName and puts the columns in variables
name1, name2, ..., namek which be quoted or unquoted.
readcols(FileName,vector("name1",...,"namek")) is an alternative usage.
The file should consist of k columns of numbers separated by spaces,
commas or tabs, with MISSING values indicated by '?' or '.'. See topics
'vecread_file' and vecread() for a complete description of the file
format, including 'skip', 'skipthru', 'go', and 'stop' characters.
For all usages, the number of variable names must divide the total
number of data values.
Variable names from file
readcols(FileName), with no variable names provided, does the same,
except that the names are taken from the first non-blank line of the
file, with data assumed to start on the next line. An informative
message about the variables created is printed.
Forms for filename
FileName can take two forms:
A quoted string or CHARACTER scalar whose value is the file name. In
a version with windows, when FileName is "", you can select the file
using a dialog box. A variant is keyword phrase file:FileName.
The keyword phrase string:CharVector, where CharVector is a CHARACTER
scalar or vector which is "read" instead of a file. When
length(CharVector) > 1, each element starts a new line. Any newline
characters '\n' terminate lines. In windowed versions, string:CLIPBOARD
can be useful. See vecread(), 'CLIPBOARD'.
Reading CHARACTER data
readcols(FileName,name1,name2,...,namek, bywords:T) and
readcols(FileName, bywords:T) do the same, except that CHARACTER vectors
are created.
readcols(FileName,name1,name2,...,namek, realorchar:T) and
readcols(FileName, realorchar:T) do the same, except both REAL and
CHARACTER vectors may be created. If the first value in a column is
readable as a number, the corresponding variable will be REAL; otherwise
the variable will be CHARACTER.
Other keywords
readcols() recognizes the same keyword phrases as vecread(), except
'startline:M' and 'bylines:T'. These include skip:skipChar,
stop:stopChar, go:goChar, skipthru:skipthruChar, bypass:m, quiet:T or F,
and echo:T or F. You can't use 'bywords:T', 'bychar:T' or 'byfields:T'
with 'realorchar:T'. See vecread().
Examples
Examples:
Cmd> readcols("hald.txt",x1,x2,x3,x4,y)
Cmd> readcols(file:"hald.txt",vector("x1","x2","x3","x4","y"))
both create variables, x1, x2, x3, x4 and y from the five columns of
data in hald.txt.
Cmd> readcols(string:"x y\n 1 2\n 7 9\n ? 4")
Cmd> readcols(string:vector("x y","1 2","7 9","? 4"))
both of which have the same effect as
Cmd> x <- vector(1,7,?); y <- vector(2,9,4)
Cross references
See also topics readdata(), vecread(), 'macros'.
Gary Oehlert
2005-08-12