slice
Syntax
slice(obj, index)
or
slice(obj, rowIndex, [colIndex])
Arguments
obj is a matrix or a table.
Details
For slice(obj, index):
If obj is a matrix:
If index is a scalar, return a vector indicating a column.
If index is a vector or a pair, return a matrix of selected columns.
If obj is a table:
If index is a scalar, return a dictionary indicating a row.
If index is a vector or a pair, return a table of selected rows.
For slice(obj, rowIndex, [colIndex]):
If obj is a matrix:
If rowIndex and colIndex are both scalars, return a scalar indicating the value of specified element of the matrix.
If rowIndex and colIndex are both vectors or pairs, return a matrix of selected rows and columns.
If obj is a table:
If rowIndex and colIndex are both scalars, return a scalar indicating the value of specified element of the table.
If rowIndex and colIndex are both vectors or pairs, return a table of selected rows and columns.
To get a particular row or column from a table, consider using function col or row.
Examples
If obj is a matrix:
$ m=1..9$3:3
m.slice(0);
[1,2,3]
$ m.slice([0]);
#0 |
---|
1 |
2 |
3 |
$ m.slice(0:2);
#0 |
#1 |
---|---|
1 |
4 |
2 |
5 |
3 |
6 |
$ m.slice(0 2);
#0 |
#1 |
---|---|
1 |
7 |
2 |
8 |
3 |
9 |
$ m.slice(0,1);
4
$ m.slice(0 1,0 1);
#0 |
#1 |
---|---|
1 |
4 |
2 |
5 |
$ m.slice(1:2,1:2);
#0 |
---|
5 |
If obj is a table:
$ t=table(`A`B`C as sym,2018.01.01..2018.01.03 as date,10 48 5 as val)
t.slice(0);
val->10
date->2018.01.01
sym->A
t.slice([0]);
sym |
date |
val |
---|---|---|
A |
2018.01.01 |
10 |
$ t.slice(0 1);
sym |
date |
val |
---|---|---|
A |
2018.01.01 |
10 |
B |
2018.01.02 |
48 |
$ t.slice(0:1);
sym |
date |
val |
---|---|---|
A |
2018.01.01 |
10 |
$ t.slice(0,1);
2018.01.01
$ t.slice(0 1,0 1);
sym |
date |
---|---|
A |
2018.01.01 |
B |
2018.01.02 |
$ t.slice(1:2,1:2);
date |
---|
2018.01.02 |