What is the easiest way to add row numbers(ASC) to a Refine project?

721 views
Skip to first unread message

Eric Jarvies

unread,
Mar 3, 2014, 9:40:59 PM3/3/14
to openr...@googlegroups.com
Hello,

What is the simplest way to add a numbered column to an existing Refine project, including some of the following options?:

-set the starting number to specific number(like 100 instead of 1).
-set the increments(like 5, 10, 15 instead of 1, 2, 3).
-set specific numbers(prefixed or suffixed) based on given value(s) from data in another column.

Thanks,

Eric

Martin Magdinier

unread,
Mar 3, 2014, 10:13:57 PM3/3/14
to openrefine
Eric,

Have you tried to play around rowIndex+1  GREL expression to add a new index column?

Martin 

--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openrefine+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Eric Jarvies

unread,
Mar 3, 2014, 10:53:02 PM3/3/14
to openr...@googlegroups.com
Thank you Martin... that has got me going in the right direction, e.g.- cells['flag'].value[0] + '-' + rowIndex

Eric

Eric Jarvies

unread,
Mar 3, 2014, 11:04:42 PM3/3/14
to openr...@googlegroups.com
Martin,

What GREL would be used if I needed the numbering to always use the same amount/quantity of characters?  In other words, if a Refine project has a few hundred thousand records, then the numbering would contain between 1 and 6 characters depending on the record and its respective count, e.g.-
1
10
100
1000
10000
100000

so if prefixing or suffixing the number to something else like a code and a time/date stamp, e.g.-
1-someCode-2014 or 1ABC1232014

you would be able to end up with the same number of characters(6 in this example) for each number on each row like this;
000001ABC1232014
100000ABC1232014

instead of(not like this);
1ABC1232014
10ABC1232014
100ABC1232014
1000ABC1232014
10000ABC1232014
100000ABC1232014

Thanks,

Eric


On Mar 3, 2014, at 8:13 PM, Martin Magdinier wrote:

Martin Magdinier

unread,
Mar 3, 2014, 11:45:12 PM3/3/14
to openrefine
You need to use padding function for this:
"0000"[0,4-value.length()] + value

Eric Jarvies

unread,
Mar 4, 2014, 1:04:43 AM3/4/14
to openr...@googlegroups.com
Martin,

When I transform using something like this;
"000"[0,3-value.length()] + value + rowIndex +cells['type'].value

i end up with the initial records looking like this; 
000250001N
and the latter records looking like this;
0002500030269A

i would like for the the entire range to contain the same number of characters(numbers), e.g.-
000250001N
to
000550269A

Thanks,

Eric

Steve W

unread,
Mar 5, 2014, 8:44:57 PM3/5/14
to openr...@googlegroups.com
If I understand your goal correctly you might try something like this:

slice("000000000000000"+(rowIndex+1)+value,-16)

Add as many 0s as you need to the front of the rowIndex and then take the last 16 or however many digits you want from the end.  Should make all numbers 16 digits long with 
000001ABC1232014
0000000002AA2014
00003BBBBBB2014
100000ABC1232014

(I'm sure there's a prettier solution somewhere)

or similarly if your ABC1232014 are all the same length and you just want 000001 - 100000 you could do something like

slice("00000"+(rowIndex+1),-6)+value

000001ABC1232014
000002ABC1232014
000999ABC1232014
100000ABC1232014


-Steve
Reply all
Reply to author
Forward
0 new messages