Convert a single row into a diagonal matrix

How can I convert a single row table into a diagonal matrix table in knime?

Input

1 3 5 2 1

Output

1 0 0 0 0

0 3 0 0 0

0 0 5 0 0

0 0 0 2 0

0 0 0 0 1

Hi,

I have attached a workflow that gets the job done via a column list loop and the missing value node. There might be more elegant ways, though as looping through columns can be really time consuming with large datasets.

This is perfect. Since the dataset is going to have one row only, I wouldn't worry about scalability.

Thanks a ton!

Maybe this one is more elegant:

Add the R Snippet Node and use this code:

knime.out <- data.frame(diag(knime.in))
colnames(knime.out) <- colnames(knime.in)

I love your solution Johannes! Very knimeish way to think