Library: | xplore |
See also: | readm writem readcsvm writecsv readascii read write |
Quantlet: | readcsv | |
Description: | reads numerical data from a csv file |
Usage: | z=readcsv(filename{,separators,fastcsv,rrow,rcol}) | |
Input: | ||
filename | name of the file | |
separators | string that contains the data separator sign (default = ";", it is used even if the string is missing or empty) | |
fastcsv | an optional scalar; if non-zero (default), the fast CSV import is used assuming that there is no special formatting using quotation marks in the file | |
rrow | 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. | |
rcol | 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. | |
Output: | ||
z | matrix containing the numerical elements of the csv file |
2;3;
3;;7
4;4;8
5;5;9
The columns and rows specified by matrices rcol and rrow are read and output in the same order as they are in the file, i.e., as if the entries of rcol and rrow are sorted.
library("xplore") readcsv("excsv.csv")
Contents of string [1,] "readm: Found 4 line(s) and 3 column(s)" Contents of z [1,] 2 3 +NAN [2,] 3 +NAN 7 [3,] 4 4 8 [4,] 5 5 9
library("xplore") readcsv("excsv.csv", "", 1, -1~-1)
The same example as before is used, but now the first row is omitted. Notice that the separator is an empty string, so that the default separators are used. Contents of string [1,] "readm: Found 3 line(s) and 3 column(s)" Contents of z [1,] 3 +NAN 7 [2,] 4 4 8 [3,] 5 5 9