reshape-wide-to-long

Description

reshape-wide-to-long adaptor transforms a datatable to a two-column datatable in which one column contains the column names of the original datatable and the second column is the respective value from each row.

Inputs

data Type: datatable Required: Yes The datatable in wide format.

static columns Type: list Required: No The list of columns which will not be reshaped. If unspecified, all columns will be reshaped

key column name Type: text Required: No The name of the column to which keys are added. If unspecified, defaults to key.

value column name Type: text Required: No The name of the column to which values are added. If unspecified, defaults to value.

Outputs

data Type: datatable A datatable in long format.

Examples

Example 1: Default behaviour.

Inputs:

data:

idcodecountry

1

GB

United Kingdom

2

TR

Turkey

3

US

United States

static columns: null (empty)

key column name: null (empty)

value column name: null (empty)

Outputs:

data:

keyvalue

id

1

code

GB

country

United Kingdom

id

2

code

TR

country

Turkey

id

3

code

US

country

United States

-> Transformed all the columns in the datatable, from wide to long, using the default key and value as the column names

Example 2: Reshape with static columns.

Inputs:

data:

idcodecountry

1

GB

United Kingdom

2

TR

Turkey

3

US

United States

static columns:

  1. country

key column name: null (empty)

value column name: null (empty)

Outputs:

data:

keyvalue

id

1

code

GB

id

2

code

TR

id

3

code

US

-> Transformed the columns id and code in the datatable, from wide to long, using the default key and value as the column names. The country column was not reshaped.

Example 3: Reshape with specific key column name and value column name.

Inputs:

data:

idcodecountry

1

GB

United Kingdom

2

TR

Turkey

3

US

United States

static columns:

  1. country

key column name: name

value column name: result

Outputs:

data:

nameresult

id

1

code

GB

id

2

code

TR

id

3

code

US

-> Transformed the columns id and code in the datatable, from wide to long, using the name as key column name and result as the value column name.

Last updated