Am new to using newgroup for help, but have exhausted my searching
online for a solution
I have a long list of data of associations between values with a value
to that association as follows..
(var) to (var) = (var) hits
A B 1
B A 1
A B 3
B A 3
A C 7
C A 2
And need to build a table as follows that accumulates the above:
row is (from)
column is (to)
A B C
A 0 4 7
B 4 0 0
C 2 0 0
Just can't seam to figure out how to manage this programatically.
Any help or guidance much appreciated !!!
Cheers,
Jay
Hope this wil help though not in perl, I guess the port should be
quite straightforward (note the OFS means Output Field Separator and
ORS stands for Output Record Separator)
Given the sample file:
---------------
$ cat MISCFILES/var2varHits
### (var) to (var) (hits)
### wants a result matrix as
### row is (from)
### col is (to)
### content is (sigmahits)
###
A B 1
B A 1
A B 3
B A 3
A C 7
C A 2
---------------
the 'almost meta' code here:
---------------
awk '
/^[^#]/{
froms[$1]
tos[$2]
hits[$1","$2]+=$3
}
END{
printf OFS OFS
for(t in tos){
printf t OFS
}
printf ORS
for(f in froms){
printf f OFS
for(t in tos){
printf 0+hits[f","t] OFS
}
printf ORS
}
}' MISCFILES/var2varHits
---------------
will produce:
---------------
A B C
A 0 4 7
B 4 0 0
C 2 0 0
---------------
> Thu, 05 Nov 2009 06:36:19 -0800, jay did cat :
>
>> Hi All,
>>
>> Am new to using newgroup for help, but have exhausted my searching
>> online for a solution
ooops, I didn't see your post in c.l.a. before and why didi you
multipost instead of crosspost!? Ah sorry...
The code bellow will do what you want. I hope it helps a litle
George Mpouras
while (<DATA>) { (@_) = split /\s+/; $hash{$_[0],$_[1]} += $_[2] }
print $hash{A,C};
__DATA__