cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Kwangki
Level III

How to insert multiple data without column name?

Below is JSL to make JMP table.

 

dt = New Table( "Floor Example",
     New Column( "Unit ID", Character, Nominal ),
     New Column( "Data1", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data2", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data3", Numeric, Continuous, Format( "Best", 12 ) ),
);

dtdata={
  {Unit ID = "A", Data1 = 1.1, Data2 = 2.1, Data3 = 3.1},
  {Unit ID = "B", Data1 = 1.2, Data2 = 2.2, Data3 = 3.2},
  {Unit ID = "C", Data1 = 1.3, Data2 = 2.3, Data3 = 3.3}
     };

dt << Add Rows( dtdata );

 

I'd like to insert multiple data without defining column name as follows.

    
dtdata={
  {"A", 1.1, 2.1, 3.1},
  {"B", 1.2, 2.2, 3.2},
  {"C", 1.3, 2.3, 3.3}
     };

 

Above is not right answer. Please let me know right JSL syntax.

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: How to insert multiple data without column name?

Here are a couple of options that work with JMP 13 and higher.

dt = New Table( "Floor Example",
     New Column( "Unit ID", Character, Nominal ),
     New Column( "Data1", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data2", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data3", Numeric, Continuous, Format( "Best", 12 ) ),
);

dt << add rows(nitems(dtdata));
 
dtdata={
  {"A", 1.1, 2.1, 3.1},
  {"B", 1.2, 2.2, 3.2},
  {"C", 1.3, 2.3, 3.3}
     };

 
 For Each Row(dt, dt[row(),1::ncol(dt)]=dtdata[row()]);
 
 
 //or create a function to append
 
 addrows = function({listofrows, ctbl=current data table()}, {nr,nc, i},
 	nr = nrow(ctbl);
 	nc = ncol(ctbl);
 	for(i=1, i <= nitems(listofrows), i++,
 	  ctbl << add rows(1);
 	  ctbl[nr+i, 1::nc] = listofrows[i]
 	);
 ); //end function
 
 //add the rows again to demo this  function
 
 addrows(dtdata);

 

View solution in original post

2 REPLIES 2
gzmorgan0
Super User (Alumni)

Re: How to insert multiple data without column name?

Here are a couple of options that work with JMP 13 and higher.

dt = New Table( "Floor Example",
     New Column( "Unit ID", Character, Nominal ),
     New Column( "Data1", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data2", Numeric, Continuous, Format( "Best", 12 ) ),
     New Column( "Data3", Numeric, Continuous, Format( "Best", 12 ) ),
);

dt << add rows(nitems(dtdata));
 
dtdata={
  {"A", 1.1, 2.1, 3.1},
  {"B", 1.2, 2.2, 3.2},
  {"C", 1.3, 2.3, 3.3}
     };

 
 For Each Row(dt, dt[row(),1::ncol(dt)]=dtdata[row()]);
 
 
 //or create a function to append
 
 addrows = function({listofrows, ctbl=current data table()}, {nr,nc, i},
 	nr = nrow(ctbl);
 	nc = ncol(ctbl);
 	for(i=1, i <= nitems(listofrows), i++,
 	  ctbl << add rows(1);
 	  ctbl[nr+i, 1::nc] = listofrows[i]
 	);
 ); //end function
 
 //add the rows again to demo this  function
 
 addrows(dtdata);

 

Re: How to insert multiple data without column name?

This situation is covered in the documentation. See Help > Books > Scripting Guide. There is a section about different ways to add rows to the data table. There are many examples throughout the guide. Here is the excerpt:

 

Add Rows

To add rows, send an Add Rows message and specify how many rows. You can also specify after which row to insert the new rows. The arguments can either be numbers or expressions that evaluate to numbers.

 

dt << Add Rows( 3 ); // add 3 rows to bottom of data table
dt << Add Rows( 3, 10 ); /* add 3 rows after the 10th row, moving the 11th and lower rows farther down */

 

A variation of Add Rows lets you specify an argument yielding a list of assignments.

 

Assignments can be separated with commas or semicolons.

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows(
{:name = "Peter", :age = 14, :sex = "M", :height = 61, :weight = 124}
 
);

 

or

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows(
{:name = "Peter"; :age = 14; :sex = "M"; :height = 61; :weight = 124}
 
);

 

You can send several arguments yielding lists, or even a list of lists. The following script

creates a data table with Add Rows commands of each variety:

 

dt = New Table( "Cities" );
dt << New Column( "xx", Numeric );
dt << New Column( "cc", Character, width( 12 ) );
dt << Add Rows( {xx = 12, cc = "Chicago"} ); // single list
dt << Add Rows( {xx = 13, cc = "New York"}, {xx = 14, cc = "Newark"} );
 
// several lists
dt << Add Rows(
{{xx = 15, cc = "San Francisco"}, {xx = Sqrt( 256 ), cc = "Oakland"}}
); // list of lists
a = {xx = 20, cc = "Miami"};
dt << Add Rows( a ); // evaluate as single list
b={{xx = 17, cc = "San Antonio"},{xx = 18, cc = "Houston"}, {xx = 19, cc =
"Dallas"}};
dt << Add Rows( b ); // evaluate as list of lists