Hi, I wanted to calculate cumulative frequency distribution of my data that involves several arithmetic calls. I did things in excel but its taking me forever. this is what I want to do:
var1.txt contains n observations which I have to compute for frequency which is given by 1/n and subsequently the cumulative frequency (cumfreq).
obs freq (1/n) cumfreq
2 1/7 1/7
3 1/7 1/7+1/7
4 1/7 1/7+1/7+1/7
5 1/7 1/7+1/7+1/7+1/7
6 1/7 1/7+1/7+1/7+1/7+1/7
7 1/7 1/7+1/7+1/7+1/7+1/7+1/7
8 1/7 1/7+1/7+1/7+1/7+1/7+1/7+1/7
Any help on this is very much appreciated. Bunch of thanks in advance.
Hi balajesuri, thanks for your quick reply. yes, I need the evaluated cumulative frequency. There's a small glitch though, it doesn't print the first row and as such the last cumulative frequency value is a little off to 1.
And also quick question what does $. means? thanks again
When you say first row, you mean "obs freq cumFreq", right? If so, the perl code does print this.
In perl, scalar variables begin with a "$" symbol. That's the language grammar. Likewise, perl recognizes an array identifier by "@" as in @myArrVar a hash by "%" as in %myHash .
Hi again, Thanks much for the explanation on perl syntax. Anyway, This is the sample output am getting when I run the perl script. the columns correspond to the obs, frequency and cumulative frequency, respectively. the first value in 3rd column should be in the first row so that the last row would be equal to 1. Thanks again for looking into this.
Ha, ha! Another classic example of changing requirements. Ok, here's some light:
if($. == 1) {print; next} ==> This part of the code checks if line in consideration is line #1 and if so prints the line as-is and proceeds to next line. This is because, from your initial sample in post #1, first line is the header line ( obs freq (1/n) cumfreq ).