pad function in the Factory

The pad function returns in each row of the result, the values of the column, filled (padded) with the padstring value to reach the specified length. The string can be added at the beginning (where = "begin" or by default) or at the end (where = "end") of the string, according to the value of the parameter where.


Parameters

pad(column, len, value, where)

If you are using continuous attributes, check the Flow Execution Parameters.

Parameter

Description

column

The nominal attribute used to compute the text lengths. If it is not nominal, it will be casted to nominal upon function’s computation. The column parameter is mandatory.

len

The length (number of letters) of the resulting words. The len parameter is mandatory.

value

The padstring to be added to fill the desired length, if the original word is shorter than the len. It is set to 0 as default. If the padstring is not nominal, it will be casted to nominal upon function’s computation.

where

It controls the position where the padstring is added. If it is ‘begin’, the padstrings will be added at the beginning of the word, while if it is ‘end’, the padstrings will be added at the end.


Example

The following example uses the E-commerce shipping data dataset.

Description

Screenshot

In this example, we want the ID attribute values to have the same length, which is 6 for administrative reasons.

Add a new attribute, called newID and type the following formula:

pad($"ID",6)

As we didn’t specify any value parameters, 0 is added to reach the len.

As we didn’t specify any where parameters, the values are added at the beginning of the word.

If we want to add specific values ( x ) at the end of the ID attribute’s strings, we need to add the value and where parameters to the function. The function becomes:

pad($"ID",6,'x','end')