Thread Erstellen einer diagonalen Matrix (3 answers)
Opened by kimmy at 2012-02-23 10:46

rosti
 2012-02-23 11:35
#156347 #156347
User since
2011-03-19
3212 Artikel
BenutzerIn
[Homepage]
user image
Für Kreuztabellen geht ein hash:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl

use strict;
use warnings;

my %base = (); # Ausgangsbasis
while(<DATA>){
        my $ar = [split];
        $base{$ar->[0]}{$ar->[1]} = $ar->[2] || '';
}

print "\t", join("\t", qw(A B C D E)), "\n";
foreach my $k1 (qw(A B C D E)){
        print "$k1";
        foreach my $k2 (qw(A B C D E)){
                my $val = $base{$k1}{$k2} || ''; 
                print "\t$val";
        }
        print "\n";
}


__END__
A       A       
B       A       1
C       A       3
C       B       2
D       A       2
D       B       4
D       C       3
E       A       2
E       B       2
E       C       1
E       D       3


gibt aus:

Code: (dl )
1
2
3
4
5
6
	A	B	C	D	E
A
B 1
C 3 2
D 2 4 3
E 2 2 1 3


Sieht aus wie gewünscht ;)
Last edited: 2012-02-23 11:39:30 +0100 (CET)

View full thread Erstellen einer diagonalen Matrix