cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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

Recommended Articles