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
ileshem
Level III

Take value from specific cell to create a column

Hello, 

In JSL, I want to use a specific cell value to create a column. how can I do it?

From this:

ID 
1122 
NameAge
Johan23
David34
Jack27

to This: 

IDNameAge
1122Johan23
1122David34
1122Jack27
2 REPLIES 2
jthi
Super User

Re: Take value from specific cell to create a column

For this specific case this should work:

 

Names Default To Here(1);

dt = New Table("Untitled 5",
	Add Rows(6),
	Compress File When Saved(1),
	New Column("Column 1",
		Character,
		"Nominal",
		Set Values({"ID", "1122", "Name", "Johan", "David", "Jack"})
	),
	New Column("Column 2",
		Character(16),
		"Nominal",
		Set Values({"", "", "Age", "23", "34", "27"})
	)
);
wait(1);
//get column name
columnNameCell = dt[1,1];
//get cell value
valueCell = dt[2,1];
//Rename columns
Column(dt,1) << Set Name(dt[3,1]);
Column(dt,2) << Set Name(dt[3,2]);
//Remove extra rows
dt << Delete Rows([1,2,3]);
//create new column
dt << New Column(columnNameCell, Character, Nominal, << Set Each Value(valueCell));
//Move ID column
dt << Move Selected Columns(:ID, To First);

For modifications like this I think Data Table Subscripting is very helpful

 

-Jarmo
Craige_Hales
Super User

Re: Take value from specific cell to create a column

nice! I don't think I understood the question until I ran your answer a line at a time.

Craige