Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: xplore
See also: read readascii readm write

Quantlet: readcond
Description: reads the data according to a condition which is explicitly stated as a string.

Usage: x = readcond(file, r, c, condcols, condition)
Input:
file string containing the name of the file which should be read
r p1 x 2 matrix, it specifies, which rows should be read. Every row consists of two numbers namely r1 and r2: 1) if both numbers are positive, they specify that all rows with indices {r1,...,r2} should be read in; 2) if both numbers are negative, they specify that the rows with indices {|r1|,...,|r2|} should be excluded from reading; 3) it is not possible to mix inclusion and exclusion conditions. Note that if you enter a scalar, it will be ignored and all rows are read.
c p2 x 2 matrix, it specifies, which columns should be read. Every column consists of two numbers namely r1 and r2: 1) if both numbers are positive, they specify that all columns with indices {r1,...,r2} should be read in; 2) if both number are negative, they specify that the columns with indices {|r1|,...,|r2|} should be excluded from reading; 3) it is not possible to mix inclusion and exclusion conditions. Note that if you enter a scalar, it will be ignored and all columns are read.
condcols p3 x 1 vector, it specifies to which columns in file that is to be read the condition should be applied. Note that the columns can deviate from the parameter c, i.e. you can read data without the columns where the condition is evaluated.
condition string, specifies a valid condition. "x" is the matrix to which the condition is applied. The numeration of the columns in x follows the number of columns as specified in condcols, i.e. if you read by means of condcols 3 columns altogether and the third column is crucial for the condition, write "x[,3]".
Output:
x matrix of the data read according to the condition; Note that the vector or matrix indices refer to the matrix, which is actually read not to the original one.

Note:

Example:
;load the library xplore
library("xplore")
readcond("bostonh", 4~8,(1~4), 1, "x[,1].<0.04")

Result:
This example reads the data from "bostonh", i.e. rows
4 to 8 and columns 1 to 4, if the values in columm 1
are smaller than 0.04:

Contents of x
[1,]  0.03237        0     2.18        0
[2,]  0.02985        0     2.18        0
Example:
;load the library xplore
library("xplore")
readcond("bostonh",(93~99)|(101~102),(4~7)|(9~9), #(1,3), "(x[,1].<0.1)||(x[,2]>8)")

Result:
This example reads the data from "bostonh", i.e. rows
93 to 99 and 101 to 102, columns 4 to 7 and 9, if the
values in columm 1 (i.e. column 1 in the original data matrix)
are smaller than 0.1 or bigger than 8 in column 2
(i.e. column 3 in the original data matrix):

Contents of x
[1,]        0    0.464    6.442     53.6        4
[2,]        0    0.464    6.211     28.9        4
[3,]        0    0.464    6.249     77.3        4
[4,]        0    0.445     7.82     36.9        2
[5,]        0     0.52    6.727     79.9        5
[6,]        0     0.52    6.781     71.3        5



Author: M. R. Fengler, 20011119
(C) MD*TECH Method and Data Technologies, 05.02.2006