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
dadawasozo
Level IV

how to put a list into a table cell under a column

Hi,

I created variables that are list. I want to create new column that under if statement will fill up the cell with those variables. So I can get table as below. How can I add list into a cell?

dadawasozo_0-1677200258932.png

 

A={"96", "104", "112", "120"};
B={"1", "100", "111", "121"};
C={"6", "14", "112", "129"};
D={"9", "124", "132", "160"};

dt << New column("Value", Expression, formula(
	
	if (
		:Mode=="A" , A,
		:Mode=="B" , B,
		:Mode=="C" , C,
		:Mode=="D" , D,
		
		
	)
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: how to put a list into a table cell under a column

Your code works fine for me

txnelson_0-1677214021020.png

Names Default To Here( 1 );
dt = Current Data Table();

A = {"96", "104", "112", "120"};
B = {"1", "100", "111", "121"};
C = {"6", "14", "112", "129"};
D = {"9", "124", "132", "160"};

dt << New Column( "Value",
	Expression,
	formula(
	
		If(
			:Mode == "A", A,
			:Mode == "B", B,
			:Mode == "C", C,
			:Mode == "D", D
		)
	)
);
Jim

View solution in original post

jthi
Super User

Re: how to put a list into a table cell under a column

Besides missing few closing brackets and having extra , I don't see issues with the script as @txnelson also said

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(5),
	Compress File When Saved(1),
	Set Header Height(46),
	New Column("Mode", Character, "Nominal", Set Values({"A", "C", "A", "A", "D"}))
);

A = {"96", "104", "112", "120"};
B = {"1", "100", "111", "121"};
C = {"6", "14", "112", "129"};
D = {"9", "124", "132", "160"};

dt << New Column("Value",
	Expression,
	formula(
	
		If(
			:Mode == "A", A,
			:Mode == "B", B,
			:Mode == "C", C,
			:Mode == "D", D
		)
	)
);

If you need to have a formula and not values in those cells, I would suggest checking out Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute  as it will most likely prevent some issues which might occur.

-Jarmo

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: how to put a list into a table cell under a column

Your code works fine for me

txnelson_0-1677214021020.png

Names Default To Here( 1 );
dt = Current Data Table();

A = {"96", "104", "112", "120"};
B = {"1", "100", "111", "121"};
C = {"6", "14", "112", "129"};
D = {"9", "124", "132", "160"};

dt << New Column( "Value",
	Expression,
	formula(
	
		If(
			:Mode == "A", A,
			:Mode == "B", B,
			:Mode == "C", C,
			:Mode == "D", D
		)
	)
);
Jim
dadawasozo
Level IV

Re: how to put a list into a table cell under a column

Hi Jim,

Your are right. I 'm not sure what was the problem that it wasn't working previously. It works after I close JMP and reopen it.

jthi
Super User

Re: how to put a list into a table cell under a column

Besides missing few closing brackets and having extra , I don't see issues with the script as @txnelson also said

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(5),
	Compress File When Saved(1),
	Set Header Height(46),
	New Column("Mode", Character, "Nominal", Set Values({"A", "C", "A", "A", "D"}))
);

A = {"96", "104", "112", "120"};
B = {"1", "100", "111", "121"};
C = {"6", "14", "112", "129"};
D = {"9", "124", "132", "160"};

dt << New Column("Value",
	Expression,
	formula(
	
		If(
			:Mode == "A", A,
			:Mode == "B", B,
			:Mode == "C", C,
			:Mode == "D", D
		)
	)
);

If you need to have a formula and not values in those cells, I would suggest checking out Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute  as it will most likely prevent some issues which might occur.

-Jarmo