Link to home
Start Free TrialLog in
Avatar of Europa MacDonald
Europa MacDonaldFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Counting the frequency of values in columns of data

I have columns of numerical data, with which I have to identify and count which numbers are present in each individual column.

so, I can have between four and twelve columns, but if it is easier just to code for four at the moment, that would be great. There is likely to be between 30 and 70 different numbers.

so if the data looked like this

123 123 165 134
134 123 165 134
165 165 165 165
243 243 245 165
245 165 245 123
234 123 165 123
123 165 165 245
134 123 165 245
165 165 123 245

I need some code which will create an output like this or similar so that I can import it into MS Excel spreadsheet.

col 1

123 2
134 2
165 2
234 1
243 1
245 1

col 2

123 4
134 0
165 4
234 1
243 1
245 0

col 3

123 1
134 0
165 6
234 0
243 0
245 2

col 4

123 2
134 2
165 2
234 0
243 0
245 3

Thankyou in advance
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Europa MacDonald

ASKER

thanks Arnold. If I was ti have that data in a file called data.txt, and wanted the PERL script to read the file, what changes would be needed ?
Thanks
You would use
open FILE, "/path/to/file" || die "unable to open file:$! \n";
Replace STDIN with FILE in the loop



At the end close(FILE);
Ok I have done that but it doesnt seem to work, as there is no change in the original file.

All I get is the flash of the PERL command dialogue box. Can I slow that down ?

How do I out put the data to a separate file ?

Thanks
Open a command window, then run the perl script within it. Note the location
Or refirect the output to a text file.
Thescriptfile.pl > %userprofile%\downloads\outputfile.csv
Notepad %userprofile%\downloads\outputfile.csv