Usage: |
z = read(file{, rows, cols, rowcond, colcond})
|
Input: |
| file | string with the name of the file to be read
|
| rows | an optional p1 x 2 matrix (if you enter a scalar, it will be ignored) specifies, which rows should be
read. Every row consists of two numbers, r1 and r2: 1) if both numbers are positive, they specify
that rows with indices {r1,...,r2} should be read in; 2) if both number are negative, they specify
that rows with indices {|r1|,...,|r2|} should be excluded from reading; 3) it is not possible to mix
inclusion and exclusion conditions. If the parameter is omitted or is a scalar, all rows are read.
|
| cols | an optional p2 x 2 matrix (if you enter a scalar, it will be ignored) specifies, which columns should be
read. Every column consists of two numbers, r1 and r2: 1) if both numbers are positive, they specify
that columns with indices {r1,...,r2} should be read in; 2) if both number are negative, they specify
that columns with indices {|r1|,...,|r2|} should be excluded from reading; 3) it is not possible to mix
inclusion and exclusion conditions. If the parameter is omitted or is a scalar, all columns are read.
|
| rowcond | an optional m1 x 1 vector (if you enter a scalar, it will be ignored) specifies, which rows should be
read. If rowcond[i] is non-zero, the i-th row is read in; if rowcond[i] equals zero, the i-th row is excluded from
reading; if the length of rowcond is smaller than the number of rows, the vector is recycled, that is
rowcond[i mod m1] is used.
|
| colcond | an optional m2 x 1 vector (if you enter a scalar, it will be ignored) specifies, which columns should be
read. If colcond[i] is non-zero, the i-th column is read in; if colcond[i] equals zero, the i-th column is excluded from
reading; if the length of colcond is smaller than the number of columns, the vector is recycled, that is
colcond[i mod m2] is used.
|
Output: |
| z | matrix |
- Example:
write(reshape(1:15,#(3,5)),"my_data.dat")
read("my_data.dat")
- Result:
Contents of readVar
[1,] 1 4 7 10 13
[2,] 2 5 8 11 14
[3,] 3 6 9 12 15
- Example:
read("pullover.dat",1~5)
- Result:
Just first five observations from pullover data are read.
Contents of readVar
[1,] 230 125 200 109
[2,] 181 99 55 107
[3,] 165 97 105 98
[4,] 150 115 85 71
[5,] 97 120 0 82
- Example:
read("pullover.dat",0,-4~-4)
- Result:
The last column - variable "presence of shop assistant" is excluded.
Contents of readVar
[ 1,] 230 125 200
[ 2,] 181 99 55
[ 3,] 165 97 105
[ 4,] 150 115 85
[ 5,] 97 120 0
[ 6,] 192 100 150
[ 7,] 181 80 85
[ 8,] 189 90 120
[ 9,] 172 95 110
[10,] 170 125 130
- Example:
price = read("pullover.dat",0,2~2) ; read only variable "price"
rowcond = price < 100 ; find out which observations have price lower than 100
read("pullover.dat",0,0,rowcond)
- Result:
Only observations with variable "price" lower than 100 are imported.
Contents of readVar
[1,] 181 99 55 107
[2,] 165 97 105 98
[3,] 181 80 85 111
[4,] 189 90 120 93
[5,] 172 95 110 86
- Example:
read("pullover.dat",0,0,0,#(0,1))
- Result:
Every second column (columns 2 and 4) is read.
Contents of readVar
[ 1,] 125 109
[ 2,] 99 107
[ 3,] 97 98
[ 4,] 115 71
[ 5,] 120 82
[ 6,] 100 103
[ 7,] 80 111
[ 8,] 90 93
[ 9,] 95 86
[10,] 125 78