The Expand Vector Column add-in will convert an expression column containing a vector into a set of columns containing the elements of the vector.
The TestVec.jmp data table can be used for demonstration.
Add-in courtesy john.sall
very helpful cool trick:+0 to use the index to access the values inside the vector - instead of the respective row.why sum()?suggestions for improvements in a future version of the addIn:- at the moment, the code works well if the vectors in all cells have the same length - and none of them is empty().-> by encapsulating the formula with Try() one could make it even work without complaints for cells with variable vector length.- maybe: first find the longest vector and then use this length to determine the number of columns to add.
The source code for the add-in is open. Feel free to enhance it and post your own version back to the File Exchange. I'm sure the Community would appreciate your additions.
// expandVector.jsl // With this script,the user selects column containing vectors of arbitrary length,and the // script creates a set of columns with the elements of the vector. // Test Table: // New Table( "TestVec",Add Rows(5),New Column("A",Expression,Vector,Set Values({[1,2,3,4,5],[5,4,3,2,1],Empty(),[2,1]}))); Names Default To Here( 1 ); dt = Current Data Table(); If( Is Empty( dt ), throw() ); names = dt << Get Selected Columns; if(not(nitems(names)),Caption("no column selected"); throw()); Caption("expanding "|| Char(nitems(names))||" vector column(s) ..."); wait(0); for each ({col}, names, if ((col<<GetDataType)!="Expression",continue()); colName = col << get name(); nDim = col maximum(Try(Nitems(col),.)); for(i=1,i<=nDim,i++, Eval(EvalExpr(NewColumn(Expr(colName||"["||Char(i)||"]"),Numeric,Formula(Try(Sum(Subscript(Expr(Name Expr(col))+0,Expr(i)))))))); ); dt << run formulas(); ); Caption(remove)