cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Craige_Hales
Super User
Data table subscripting

You've always been able to subscript columns in a data table as one dimensional vectors.  In JMP 13 you can subscript a data table as a two dimensional array.  Here are some examples using big class.   (The very last example shows the column subscripting.)

 

12872_pastedImage_0.png

 

 

 

dt = Open("$SAMPLE_DATA\Big class.jmp");

// fetch a scalar; neither subscript is a matrix
dt[ 4, "height"]; // 66

// fetch a matrix if either is a matrix, even if 1x1
dt[ [4], "height"]; // [66]
dt[ 4, {height}]; // [66]

// fetch a list if character columns are involved. 
// notice the matrix is reversing the order
dt[ 4::2, "name"]; // {"JACLYN", "JANE", "LOUISE"}

// fetch an entire dimension using 0 for a subscript
dt[ 1,0 ]; // {"KATIE", 12, "F", 59, 95}

// fetch by column names
dt[[1,3,5],{height,weight}]; // [59 95,  55 74, 52 64]

// fetch by column numbers in matrix or list
dt[[1,3,5],[2 4 5]]; // [12 59 95, 12 55 74,  12 52 64]
dt[[1,3,5],{2,4,5}]; // [12 59 95, 12 55 74,  12 52 64]

// assignments work too.  first, fetch a copy
copydt = dt[0,0]; // make a list of the table's data

// Clear the table
dt[0,0] = .; // all rows and cols are missing

// restore the table
dt[0,0] = copydt;

// reverse two columns, top to bottom and left to right
// (do it again to repair the table!)
dt[1::nrows(dt),{name,sex}] = dt[nrows(dt)::1,{sex,name}];

// set from a matrix
dt[2::3,{age,height,weight}] = [22 70 190, 23 73 200 ];


// column subscripting still works...
dt:name[4::7]; // {"JACLYN", "LILLIE", "TIM", "JAMES"}

 

 

The data table subscripting makes it easier to work with a table than before; you can swap rows or columns with a single (slightly complicated) statement, or copy blocks from one table to another, or extract a matrix from a subset of the table using a matrix of rows and a list of columns that identify the subset.

Last Modified: Jun 25, 2019 5:11 PM
Comments