Create n columns

Hi,

I have a column with 5 rows, something like this:

Col1
1
2
3
4
5

and I want to create 12 columns with the exact same data as my first column. The number of columns would be decreasing once a month. What I want is to be able to select how many columns I want to be created, wether is manual configuring the node/script or user input.

Any ideas how to do this?

Hi @LuisMP and welcome to the Knime Community.

This can easily be done with a Counting Loop since you know how many columns you want, and you can close the loop with a Loop End (Column Append) since you want to append the results as columns. Add a Variable Creator to define your number of columns (n).

Something as simple as this will do the job:
image

I used a variable called “num_of_col” to define “n”, and I set it to 12:
image

And I use this variable in the Counting Loop Start to define how many iterations I want:
image

This is my starting table:
image

Results:

Of course, if your table have other tables that you do not want to duplicate, there will be additional manipulations to be done.

And you can also easily rename the columns using Column Rename (Regex) since they have patterns in their current name.

Here’s the workflow: Duplicate n columns.knwf (11.5 KB)

5 Likes

Another way could be transposing the data

I once heared transpose is not the fastest node so it might depend on your data size but I thought sharing doesn’t help
Additional potential renaming steps as @bruno29a kindly already pointed out.
br

Thank you so much! this really made the work easier for me

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.