Apply function on multiple columns

134 views
Skip to first unread message

wl

unread,
Dec 6, 2019, 1:28:02 AM12/6/19
to OpenRefine
Hi! 

Is there a way in OpenRefine to apply a function on multiple columns?
When I have a dataset like this (with a large number of columns) and want to replace the "NA" by "NULL", like one can do in Excel with Find&Replace on the whole sheet:

ID	A	B	C
1	3	2	4
2	NA	NA	7
3	0	1	NA

I know I can do something like this to loop over all columns of a dataset:
forEach(row.columnNames,cn,cells[cn].value.replace('NA','NULL'))
Or just select some columns of interest:
forEach(['A','B','C'],cn,cells[cn].value.replace('NA','NULL'))

But this returns the result of the function applied on the columns in an array (as new column).
Can I write back the result of the replace (or any other) function to the current column in OR?

Wolf

Owen Stephens

unread,
Dec 6, 2019, 6:21:16 AM12/6/19
to OpenRefine
As long as you are using a recent version of OpenRefine, you can do this:

  1. In "All" column click for drop down menu and choose "Transform"
  2. Write your transformation in the Expression dialogue and click OK
  3. You will be prompted to select which columns to apply it to - you can select all

Best wishes

Owen

wl

unread,
Dec 6, 2019, 6:56:00 AM12/6/19
to OpenRefine
Many thanks for your help, Owen!

I've somehow missed this very useful feature...

Best,
Wolf
Reply all
Reply to author
Forward
0 new messages