Group Values in Each Column for an Aggregation
【Question】
3 10 11 21 30 34 36 40 41 53 58 64 68 76 85 87 91 94 101 104 116 123
3 10 20 21 23 34 36 39 41 53 56 64 68 76 85 87 91 94 101 105 115 119
1 10 19 21 24 34 36 39 42 53 56 64 68 76 85 87 91 94 101 105 115 121
3 9 19 21 30 34 36 40 42 53 58 64 68 76 85 87 91 94 101 104 116 123
3 10 14 22 29 34 37 39 41 54 58 64 68 76 85 87 91 94 97 105 113 119
3 9 20 21 23 34 36 39 42 53 56 64 68 76 85 87 91 94 101 104 115 119
1 10 19 21 23 34 36 39 45 53 56 64 68 76 85 87 91 94 101 104 115 121
I need to find the number of each unique integer in each column of the above text file and export each unique integer and their frequency. For example, there are five 3s, two 1s in the first column and there are five 10s in the second column, etc.
【Answer】
Batch processing in Java is complicated. But that is easy in SPL (Structured Process Language):
A |
|
1 |
=file("E:\\s.txt").import(;,"") |
2 |
=A1.fno().(A1.field(~).groups(~:number;count(~):count)) |
3 |
=A2.news(~;A2.#:column,number:number,count:count) |
A1: Import s.txt;
A2: Group each column and perform count for every integer and create a two-dimensional table made up of no field (numbers in the field) and count (count of those numbers).
A3: Create a two-dimensional table of 3 fields – column, number and count based on A2. Here’s the final result:
An SPL script can be embedded into a Java application (See How to Call an SPL Script in Java).
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL