I may be a bit redundant, but here is an alternative way of handling this given the requirement to output to a csv file. It uses data table manipulation to get the data into the correct form, and then writes the data table to a csv file
Names Default To Here( 1 ); // Create some sample data dt = New Table( "Example", add rows( 72 ), New Column( "c1", formula( Random Uniform( 1, 500 ) ) ), New Column( "c2", formula( Random Uniform( 1, 500 ) ) ), New Column( "c3", formula( Random Uniform( 1, 500 ) ) ) ); dt << run formulas; dt:c1 << delete property( "formula" ); dt:c2 << delete property( "formula" ); dt:c3 << delete property( "formula" ); // Get the list of columns colNamesList = dt << get column names( string, numeric ); // Loop across the columns and process them For( i = 1, i <= N Cols( dt ), i++, // Create a new table will only the single column dtTemp = dt << subset(invisible, selected rows( 0 ), columns( Column( colNamesList[i] ) ) ); // If there are not 96 rows, add them If( N Rows( dtTemp ) < 96, rowCount = N Rows( dt ); dtTemp << add rows( 96 - rowCount ); For( k = rowCount + 1, K <= 96, k++, Column( dtTemp, colNamesList[i] )[k] = 0 ); ); // Create a sequence column to allow for proper splitting of the data dtTemp << New Column( "sequence", formula( x = Mod( Row(), 8 ); If( x == 0, x = 8 ); x; ) ); dtTemp << run formulas; // Split the data into 8 columns.....if this should be 12 just change the sequence formula above dtSplit = dtTemp << Split(invisible, Split By( :sequence ), Split( Column( dtTemp, colNamesList[i] ) ), Sort by Column Property ); dtSplit << run formulas; // Close the un needed temporary data table Close( dtTemp, nosave ); // Change the output preferences to get rid of headers current_pref = Char( Arg( Parse( (Char( Get Preferences( Export settings ) )) ), 1 ) ); // Set prefs (comma delimited, no headers) Pref( Export Settings( End Of Field( Comma ), Export Table Headers( 0 ) ) ); // Save csv file dtSplit << save( "$TEMP\" || colNamesList[i] || ".csv" ); //Restore oribinal prefs Eval( Parse( "pref(" || current_pref || ")" ) ); // Close the un necessary table Close( dtSplit, nosave ); );
I suspect that as a new JMP user, your mindset might still be that of a spreadsheet user. I do not know the destination of the CSV file, but you can do much in JMP using a tall table layout.
Why do you need the 8x12 layout? Why do you need to export the matrices as CSV files?
We might be able to help you use JMP to your advantage if we knew where this analysis was going.
See Help > Scripting Index. Click the drop down button and select Functions. Search for As Table() function.
Ok, this updated version of the script should do the trick:
Names Default to Here( 1 ); dt = Open( "Example.jmp" ); table = Associative Array(); For( c = 1, c <= N Col( dt ), c++, data = Column( dt, c ) << Get As Matrix; If( N Row( data ) < 96, data |/= J( 96 - N Row( data ), 1, 0 ); ); table[Column( dt, c ) << Get Name] = Transpose( Shape( data, 12, 8 ) ); ); content = table << Get Contents; For( t = 1, t <= N Items( content ), t++, dt = As Table( content[t] ); Close( dt, Save( content[t] || ".CSV" ) ); );
Unfortunately, I do not know how to suppress the first line with the header names in the CSV files. Perhaps someone else knows. We could immediately read the file back as text, delete the first line, and save it out again.
Please be patient. I am having difficulty with saving the CSV file for some unknown reason. I am working with Technical Support.
While I wait for them to reply, I want to be sure that you want to replace the first row of the CSV file (original data column headers) with just the name of the original data column name.
There are no labels assigned to this post.