cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
vkkumar321
Level I

How do I write a list to a column in a new data table?

I'm trying to extract a list of elements from a column that satisfies a condition. I'd like to write this list to a data table with the same column name so I can keep track of my rows. I'd like to keep appending to this list with time. For example:

 

p = :col_name[condition << get selected rows];

I want to write this list to a table with the same column name and append to this table.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I write a list to a column in a new data table?

Here are a couple of examples on how I would proceed

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

loop = 5;
target = "NPN1";

dtFinal = New Table( "Results", New Column( target ) );

// Generate some random selected rows
For( i = 1, i <= loop, i++,
	Current Data Table( dt );
	For Each Row(
		If( Random Uniform( 1, 100 ) > 95,
			Row State( Row() ) = Selected State( 1 )
		)
	);
	theRows = dt << get selected rows;
	dtInt = New Table( "temp", invisible, New Column( target, set values( theRows ) ) );
	dtFinal = dtFinal << concatenate( dtInt, append to first table( 1 ) );
	Close( dtInt, nosave );
);
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

loop = 5;
target = "NPN1";
theRows = [];

For( i = 1, i <= loop, i++,
	Current Data Table( dt );
	For Each Row(
		If( Random Uniform( 1, 100 ) > 95,
			Row State( Row() ) = Selected State( 1 )
		)
	);
	theRows = theRows |/ (dt << get selected rows);
);

dtFinal = New Table( "Results", New Column( target, set values( theRows ) ) );
Jim

View solution in original post

3 REPLIES 3
jthi
Super User

Re: How do I write a list to a column in a new data table?

Do you already have the datatable or will you generate after getting list of rows? When you create new columns, you should also check data type and modeling type of the original column and keep them same (not done here):

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt << Select Rows([1,2,3,10]);

col_name = "name";
p = Column(dt, col_name)[dt << get selected rows];

//create new table
dt_rows = New Table("collection",
	New Column(col_name, Character, "Nominal", Set Values(p))
);

//add to existing
col_name = "age";
p = Column(dt, col_name)[dt << get selected rows];
dt_rows << New Column(col_name, Numeric, "Ordinal", Set Values(p));
-Jarmo
txnelson
Super User

Re: How do I write a list to a column in a new data table?

Here are a couple of examples on how I would proceed

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

loop = 5;
target = "NPN1";

dtFinal = New Table( "Results", New Column( target ) );

// Generate some random selected rows
For( i = 1, i <= loop, i++,
	Current Data Table( dt );
	For Each Row(
		If( Random Uniform( 1, 100 ) > 95,
			Row State( Row() ) = Selected State( 1 )
		)
	);
	theRows = dt << get selected rows;
	dtInt = New Table( "temp", invisible, New Column( target, set values( theRows ) ) );
	dtFinal = dtFinal << concatenate( dtInt, append to first table( 1 ) );
	Close( dtInt, nosave );
);
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

loop = 5;
target = "NPN1";
theRows = [];

For( i = 1, i <= loop, i++,
	Current Data Table( dt );
	For Each Row(
		If( Random Uniform( 1, 100 ) > 95,
			Row State( Row() ) = Selected State( 1 )
		)
	);
	theRows = theRows |/ (dt << get selected rows);
);

dtFinal = New Table( "Results", New Column( target, set values( theRows ) ) );
Jim
vkkumar321
Level I

Re: How do I write a list to a column in a new data table?

Thank you. This is helpful.