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

Replacing value in a column

I am trying to conditionally replace value in 2 columns in a table below. For example if fruit is mango replace color to black and quantity with 10.Is there an easy way to do this?

 

Fruit   Color      Quantity

Apple  Red         1

Mango Yellow      2

Orange Orange    3

Banana  Yellow      2

Grape    Green      1

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Replacing value in a column

Here are 3 different ways to do this:

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

For Each Row(
	If( :Fruit == "Mango",
		:Color = "Black";
		:Quantity = 10;
	)
);
Names Default To Here( 1 );
dt = Current Data Table();

For( i = 1, i <= N Rows( dt ), i++,
	If( :Fruit[i] == "Mango",
		:Color[i] = "Black";
		:Quantity[i] = 10;
	)
);
Names Default To Here( 1 );
dt = Current Data Table();

Try( :Color[dt << get rows where( :Fruit == "Mango" )] = "Black" );
Try( :Quantity[dt << get rows where( :Fruit == "Mango" )] = 10 );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Replacing value in a column

Here are 3 different ways to do this:

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

For Each Row(
	If( :Fruit == "Mango",
		:Color = "Black";
		:Quantity = 10;
	)
);
Names Default To Here( 1 );
dt = Current Data Table();

For( i = 1, i <= N Rows( dt ), i++,
	If( :Fruit[i] == "Mango",
		:Color[i] = "Black";
		:Quantity[i] = 10;
	)
);
Names Default To Here( 1 );
dt = Current Data Table();

Try( :Color[dt << get rows where( :Fruit == "Mango" )] = "Black" );
Try( :Quantity[dt << get rows where( :Fruit == "Mango" )] = 10 );
Jim
ENTHU
Level IV

Re: Replacing value in a column

Thanks !This works.What if I dont know the value in columns.

If fruit is mango then I want to replace Quantity column value by color column value.

ENTHU
Level IV

Re: Replacing value in a column

I was able to extend the for loop to replace values in the columns