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
hogi
Level XIII

grouped Shuffle

In Big Class, students have to write a letter to another student with the same age (student A writing to student A is OK).
Which Colum Formula can I use to add name_2?

The formula should be fast even with mio of rows.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: grouped Shuffle

Combine Col At() and Col Shuffle()

Names Default To Here(1);

dt = open("$SAMPLE_DATA/Big Class.jmp");

new_col = dt << New Column("Shuffle",
	Character,
	Nominal,
	Formula(Col At(:name, Col Shuffle(:age), :age))
);

I didn't verify the results or test the speed

-Jarmo

View solution in original post

4 REPLIES 4
hogi
Level XIII

Re: grouped Shuffle

workaround: dummy table - shuffle - join

Names Default to Here(1);
dt1 = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
New Column( "Rank1",	Formula( Col Rank( 1, :age ) ));
New Column( "Rank2",	Formula( Col Rank( random integer (100000), :age ) ));

New Column( "name 2", Character,	"Nominal",	Formula( :name ));
New Column( "age 2", Formula( :age ));

dt2 = dt1 << Subset( All rows, Selected columns only( 0 ) );

dt1 << Join(
	With( dt2 ),
	Match Flag( 0 ),
	Suppress main table formula evaluation( 0 ),
	Select( :name, :age ),
	SelectWith( :name 2, :age 2 ),
	By Matching Columns( :age = :age, :Rank1 = :Rank2 ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 1 )
);

hogi_0-1770200737363.png

 

hogi
Level XIII

Re: grouped Shuffle

Workaround that doesn't work: Self join
why?

Names Default to Here(1);
dt1 = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
New Column( "Rank1",	Formula( Col Rank( 1, :age ) ));
New Column( "Rank2",	Formula( Col Rank( random integer (100000), :age ) ));

New Column( "name 2", Character,	"Nominal",	set each value( :name ));
New Column( "age 2", set each value ( :age ));

//dt2 = dt1 << Subset( All rows, Selected columns only( 0 ) );

dt1 << Join(
	With( dt1 ),
	Select( :name, :age ),
	SelectWith( :name 2, :age 2 ),
	By Matching Columns( :age = :age 2, :Rank1 = :Rank2 ),
	Drop multiples( 0, 0 ),
	Include Nonmatches( 1, 1 )
);

hogi_2-1770201078373.png

jthi
Super User

Re: grouped Shuffle

Combine Col At() and Col Shuffle()

Names Default To Here(1);

dt = open("$SAMPLE_DATA/Big Class.jmp");

new_col = dt << New Column("Shuffle",
	Character,
	Nominal,
	Formula(Col At(:name, Col Shuffle(:age), :age))
);

I didn't verify the results or test the speed

-Jarmo
hogi
Level XIII

Re: grouped Shuffle

I was stuck with col shuffle():
how can I convert the grouped index to a row index?

Ah, sure, use the grouped index as input for col at(idx, byGroup) -  perfect match!
Nice example for the new functionality.

Recommended Articles