I’m not very familiar with KNIME - mostly I use Mathematica… Now I face a “problem” which should not be one. I simply want to get the first n (say 50) columns from a larger table. I tried with a table creator and appended a counter (from 1 to 50) the transposing and tried to use the reference column filter, but this did not work. Can anyone give me a hint?
Greetings from Hanau
Hello Mike (@mgamer)
I believe you were very close to the solution. Hope the solution here attached is of help to your question.
20200504 Pikairos Select first n columns of a table.knwf (62.8 KB)
All the best
You can use a TransposeNode, then “RowFilter by number” and then another TransposeNode.
If you want you can parametrize row number by flow variable in Row Filter Node.
KNIME_form_23302_pigreco.knwf (10.9 KB)
Hi @mgamer, Mike
The answer to this question can be found in your post Select columns of table at random . The Sampling node makes it possible to select the first n (say 50) columns.
I suggest using the Extract Column Header node and no prefixes in the configurations then by using the Column Filter node and this regex pattern, you can filter the first 50 columns:
After filtering, you can use the Insert Column Header node to have your original column headers back.
Here is an example workflow:
23302-1-1.knwf (35.0 KB)
I’m afraid that regular expression is not applicable always because if you want to select the first 45 rows regular expression is not so simple.
It is easy. To have only the first 45 columns:
If your column headers are already numbered, you don’t need to extract and insert column headers.
To make things a bit easier for you, here is a simple method to create the regex pattern automatically. You just need to enter the number of columns in the Integer Input node (1 to 99 supported). You can convert this workflow to Component as well.
23302-1-2.knwf (45.6 KB)
We have lots of answers here, which is great! But unless am I crazy or missing some nuance - both possible - the OP is looking for the new Top k Selector node.
@armingrudd ok. But I think that the keyword of this topic is the word “range”.
You’re building a regular expression, a powerful mechanism to generate a list of sequence that are satisfying your pattern.
The fact that all word that match your pattern are sequencially numbers is a detail because you are not defining a range, but only a list. A complete list of values that satisfy the goal.
This approach, according to me, is more complex that to define a single number as boundary, independently by column names.
What do you think about my solution in my first reply?
@pigreco transposing large tables can take quite a while and you are doing it 2 times in your workflow, so I would not suggest it. In my suggestion we don’t transpose the table at all. The Transpose node in my workflow is used for column headers not the table itself.
@ScottF topic is “select first n columns”. I think the reason that our friends here are suggesting different row filtering options is that they are searching for a solution regarding @mgamer’s idea (transposing and using reference column filter).
@armingrudd thanks a lot.
I don’t understand why transpose implementation is so heavy but now I want to find another solution.
Thanks for the answer!
If you want to use the Transpose node and the Reference Column Filter node, you can filter the first row of the table > transpose > row filter (filter a range of rows by number) > transpose > and finally use the reference column filter node. But why not filtering columns directly?
23302-1-3.knwf (35.6 KB)
Indeed, I was missing something. I blame lack of caffeine.
Here is my solution
Filter columns from n to m.knwf (18.2 KB)
glad to see this got you fired up but is there anyone with a feeling that writing regex, transposing table (twice!) and other interesting approaches to this fairly simple request is a bit too much?
Well, I’m curious if there is a more straightforward solution to this problem other than using a column filter and a simple regex (or even better: a dynamic regex!).
Looking forward to learning something new.
Thinking about Java development?
Of course using some code could be the solution, but I always think about pure KNIMEing… (if regex is counted!)
A few days not KNIMEing and then such a lot of answers! Thank you very much. All of them are (different) solutions. Cool, but I often wonder why such a simple task (a one-liner in most other languages, especially Mathematica), need such solutions. KNIME is mostly table based - such basic operations should be implemented directly, just my opinion.