Hi,
I want to create a column with values 1,2,3 - N to label unique values in another column.
In the community, there are several similar posts
How to create a new column with numerical number based on the unique grouping of column A
Rank Unique
with a variety of solutions.
But the one cool solution I did not find up to now.
It should be
- dynamic (react on changes in the table) -> no tables/Summary, no Label to code
- independent of the column type (at least: Character + Numeric) -> no Label to code
- functional even for non-sorted tables -> no lag
- fast -> no associative array
Best: a short function like (*)
rank unique(:col1)
or an option of a function (**)
rank(:col1, << unique(1))
I found the option
rank(:col1, << tie(mode))
but I did not find a mode which produces number 1, 2,3 ... N
I thought that one can get there by using rank twice:
New Column( "step1",Formula( Col Rank( :sex, <<tie( "average" ) ) ));
New Column( "step2",Formula( Col Rank( :step1 ) ));
But step2 knows some secrets about column step1 which the user can't see:
What works:
New Column( "Rank[sex]",
Formula(
If(row() == 1,summarize(values= by(:sex)));
Contains( values, :sex )
)
);
I am still searching for (*) or (**) and hope that I can find it in the New Formula column right click context menu. But where?