This is what I have
a b c
1 1 1 1
2 1 1 1
3 1 1 1
4 1 2 2
5 1 2 2
6 1 1 1
7 1 3 3
8 2 4 4
9 1 3 3
10 1 2 2
And this is what I need to create from it:
a b c key
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 2 2 2
5 1 2 2 2
6 1 1 1 1
7 1 3 3 3
8 2 4 4 4
9 1 3 3 3
10 1 2 2 2
A sorted key would be great, but it's more important that it is fast. E.g. this one would also work.
a b c key
1 1 1 1 4
2 1 1 1 4
3 1 1 1 4
4 1 2 2 2
5 1 2 2 2
6 1 1 1 4
7 1 3 3 3
8 2 4 4 1
9 1 3 3 3
10 1 2 2 2