cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Liranlev
Level I

How to multiply rows with the same properties

Hello,

I am trying to multiply certain rows based on their other properties. For example, I want to multiply the chance of having the same first and last name.

How can I do this in code?

Thank you.

2 REPLIES 2
jthi
Super User

Re: How to multiply rows with the same properties

You want to have something like this?

jthi_0-1716206861736.png

This is one fairly easy option

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(5),
	Compress File When Saved(1),
	New Column("A", Character, "Nominal", Set Values({"E", "E", "E", "E", "E"})),
	New Column("B", Character, "Nominal", Set Values({"L", "C", "L", "L", "C"})),
	New Column("C",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([5, 7, 10, 50, 7])
	)
);

aa = Associative Array();

For Each Row(dt,
	name = :A || :B;
	If(!Contains(aa, name),
		aa[name] = 1;
	);
	Multiply To(aa[name], :C);
);

newcol = dt << New Column("R", Numeric, Continuous, Formula(
	aa[:A || :B];
));
dt << run formulas;
newcol << delete formula;
-Jarmo
txnelson
Super User

Re: How to multiply rows with the same properties

My reading of @Liranlev is different from Jarmo's.  I read the request as to be able to take the values of chance in rows 1 & 3 and multiply them together and place them in row 7, and take the value of row 7 and place them in row 8.  This seems to be treating a JMP table as one might do this in Excel, but that aside, the script below will create the table.

txnelson_0-1716208691013.png

dt = New Table("Untitled",
	Add Rows(5),
	Compress File When Saved(1),
	New Column("A", Character, "Nominal", Set Values({"E", "E", "E", "E", "E"})),
	New Column("B", Character, "Nominal", Set Values({"L", "C", "L", "L", "C"})),
	New Column("C",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Set Values([5, 7, 10, 50, 7])
	)
);

aa = Associative Array();

For Each Row(dt,
	name = :A || :B;
	If(!Contains(aa, name),
		aa[name] = 1;
	);
	Multiply To(aa[name], :C);
);

newcol = dt << New Column("R", Numeric, Continuous, Formula(
	aa[:A || :B];
));
dt << run formulas;
newcol << delete formula;
Jim