i would need a fast (therefore) awk solution for the reformation of an uncomplete weighted adjacency list to a complete sorted adjacency matrix.
example (FS=OFS=,):
should give:
I have found this thread but this does not work, because (as I think) there are missing combinations, which should be zero or 1 for self-combinations (a-a, b-b, ...).
my idea would be, to read in a 2-dimensional array with the first two columns as indices (already also with transposed indices), build the union of both indices (should not be necessary, if I already transpose the indices?!?), sort the indices, loop two times over all indices and write line for line the values of the array, including zeros for all missing index-pairs and '1' for all self-index pairs.
I can provide a few code snippets, but some problems are outside my awk-capabilities:
could you please complete my script, or (as i always learn here) provide a much more elegant solution...
I always forget, you take the input too literally. ;-)
of course is my real table much, much larger and has not only A,B,C,D.
some things i do not understand:
what means print x,h (x is not defined befor) and s=F[i] what is F - an new array, used for what?
what i would need is a loop over the sorted index (which are long names like ENSG000006234, ENSG000001345), and i do not know the number of the indices. they are given after i have read in the complete file.
two things i would need. how do i get the length of the 1. (and therefore also the 2.) dimension of the 2D-index, how can i sort these 1. dim index and than loop over this sorted index.
I want to go from
1,a,1a
1,b,1b
1,c,1c
2,a,2a
2,b,2b
3,a,3a
to
a,b,c
1,1a,1b,1c
2,2a,2b,-
3,3a,-,-
Here is what I tried
awk -F, 'BEGIN {OFS = ","} (4 Replies)
Hi everyone
I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Dear all,
i have 200 values in a file. How can i calculate a weighted average and output into a new file avg.dat?
INPUT:
file1.dat
1.3453
2.434
2.345
.....
OUTPUT:
avg.dat
file1: 1.762
Thanks.
Po (3 Replies)
Hi all,
Is there a way to convert full data matrix to linearised left data matrix?
e.g full data matrix
Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7
Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245
Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Hi All
I would like to merge multiple files with the same row and column size into a matrix format
In a folder I have multiple files in the following format
vi 12.txt
a 1
b 5
c 7
d 0
vi 45.txt
a 3
b 6
c 9
d 2
vi 9.txt
a 4 (7 Replies)
I need to weight the regression I am performing on a data file. I am not using all the numbers in the file. Here are my variables:
Y = data(,1)
X has the same bracketed first term, and the second term is
I have eight different weights I want to give, one weight corresponding to two different... (0 Replies)
Hi power user,
I have this type of data (distance list):
file1
A B 10
B C 20
C D 50I want output like this
# A B C D
A 0 10 30 80
B 10 0 20 70
C 30 20 0 50
D 80 70 50 0 Which is a distance matrix
I have tried... (0 Replies)