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.
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
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 ) );
Workaround that doesn't work: Self joinwhy?
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 ) );
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.