Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

spaced

  • Loading branch information...
commit 5c2160f85af047d3423d6c861c1f20764e027a88 1 parent 741d9ae
@mmfraser authored
View
1,995 CW1/DataSets/Communities/communitiesSpacedWithTitlesMissingGone.ss
1,995 additions, 0 deletions not shown
View
0  CW1/DataSets/Communities/communitiesSpacedWithTitlesMissingGoneZNORM.ss
No changes.
View
44 CW1/DataSets/Communities/znorm.awk
@@ -0,0 +1,44 @@
+BEGIN {records = 0; numfields = 128;}
+{
+ records++;
+ for(i=1;i<=NF;i++) {data[records,i] = $i;}
+}
+END {
+##### initialise means and stds
+ for(i=1;i<=numfields;i++) {mean[i] = 0; std[i] = 0;}
+##### calculate means
+ for(f=1;f<=numfields;f++) {
+ for(r=1;r<=records;r++) {
+ mean[f] += data[r,f];
+ }
+ mean[f] /= records;
+ }
+##### subtract means from the values
+ for(r=1;r<=records;r++) {
+ for(f=1;f<numfields;f++) { #### note "<" not "<=" ...
+ data[r,f] -= mean[f]; #### leaving the class field intact
+ }
+ }
+##### calculate stds
+ for(f=1;f<numfields;f++) {
+ for(r=1;r<=records;r++) {
+ std[f] += (data[r,f]*data[r,f]);
+ }
+ std[f] /= records;
+ std[f] = sqrt(std[f]);
+ }
+##### replace each value by std units
+ for(r=1;r<=records;r++) {
+ for(f=1;f<numfields;f++) {
+ data[r,f] /= std[f];
+ }
+ }
+
+##### finally, print out the new dataset
+ for(r=1;r<=records;r++) {
+ for(f=1;f<=numfields;f++) {
+ printf("%s ", data[r,f]);
+ }
+ printf("\n");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.