cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Liranlev
Level II

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

Recommended Articles