Sponsored Content
Top Forums Shell Programming and Scripting two-column data to matrix in AWK Post 302511293 by sramirez on Wednesday 6th of April 2011 11:14:47 AM
Old 04-06-2011
two-column data to matrix in AWK

Howdy,

I need to convert an association data matrix, currently in a two-column format, into a matrix with numbers indicating the number of associations. I've been looking around for AWK code in the list, but could not find anything. Here's an example of what I want to perform:


Code:
original data

X	A
X	B
Y	A
Y	C
Z	B
Z	C

desired output
	A	B	C
X	1	1	0
Y	1	0	1
Z	0	1	1


Thanks in advance for any advice!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

2. Emergency UNIX and Linux Support

AWK - check column data

Hi, I have a data in a file . Infile: 1 e 1.2 1.6 5 f 2.3 3.6 3 g 1.2 2.6 6 i 2.3 3.6 8 o 1.2 3.6 output: 1 e 1.2 1.6 5 f 2.3 3.6 3 g 1.1 2.6 6 i 2.2 3.5 8 o 1.0 3.4 (17 Replies)
Discussion started by: vasanth.vadalur
17 Replies

3. Ubuntu

How to convert full data matrix to linearised left data matrix?

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)
Discussion started by: evoll
8 Replies

4. Shell Programming and Scripting

convert data into matrix- awk

is it possible to count the number of keys based on state and cell and output it as a simple matrix. Ex: cell1-state1 has 2 keys cell3-state1 has 4 keys. Note: Insert 0 if no data available. input key states cell key1 state1 cell1 key1 state2 cell1 key1 ... (21 Replies)
Discussion started by: quincyjones
21 Replies

5. Shell Programming and Scripting

Printing another column using awk and input data

Hi, I have data of the following type, chr1 234 678 39 852 638 abcd 7895 chr1 526 326 33 887 965 kilj 5849 Now, I would like to have something like this chr1 234 678 39 852 638 abcd 7895 <a href="http://unix.com/thread=chr1:234-678">Link</a> chr1 526 326 33 887 965 kilj 5849 <a... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

6. Shell Programming and Scripting

3 column .csv --> correlation matrix; awk, perl?

Greetings, salutations. I have a 3 column csv file with ~13 million rows and I would like to generate a correlation matrix. Interestingly, you all previously provided a solution to the inverse of this problem. Thread title: "awk? adjacency matrix to adjacency list / correlation matrix to list"... (6 Replies)
Discussion started by: R3353
6 Replies

7. Shell Programming and Scripting

column to matrix

Hello All, I need your help in the following problem. I have a matrix of 500 columns and 1000 rows and in each cell, it is having a value range from 0 to 9. I would like to convert each column in to a matrix, according to the value in each cell (ie) 0 to 9. For each column, I need a matrix... (5 Replies)
Discussion started by: Fredrick
5 Replies

8. Shell Programming and Scripting

How order a data matrix using awk?

is it possible to order the following row clusters from ascending to descending. thanx in advance input 1 2 4 0 1 2 4 0 3 3 3 3 1 5 1 0 1 5 1 0 6 0 0 0 5 1 1 1... (4 Replies)
Discussion started by: quincyjones
4 Replies

9. Shell Programming and Scripting

Transpose matrix based on second column using awk

Hi, Is it possible to transpose the matrix like this using awk ? Many thanks in advance Input abc Name_1 0 abc Name_2 1 abc Name_3 2 abc Name_4 0.4 def Name_1 0 def Name_2 9 def Name_3 78 def Name_4 1 Output abc def Name_1 0 ... (4 Replies)
Discussion started by: quincyjones
4 Replies

10. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies
PZLAHRD(l)					      LAPACK auxiliary routine (version 1.5)						PZLAHRD(l)

NAME
PZLAHRD - reduce the first NB columns of a complex general N-by-(N-K+1) distributed matrix A(IA:IA+N-1,JA:JA+N-K) so that elements below the k-th subdiagonal are zero SYNOPSIS
SUBROUTINE PZLAHRD( N, K, NB, A, IA, JA, DESCA, TAU, T, Y, IY, JY, DESCY, WORK ) INTEGER IA, IY, JA, JY, K, N, NB INTEGER DESCA( * ), DESCY( * ) COMPLEX*16 A( * ), T( * ), TAU( * ), WORK( * ), Y( * ) PURPOSE
PZLAHRD reduces the first NB columns of a complex general N-by-(N-K+1) distributed matrix A(IA:IA+N-1,JA:JA+N-K) so that elements below the k-th subdiagonal are zero. The reduction is performed by an unitary similarity transformation Q' * A * Q. The routine returns the matrices V and T which determine Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T. This is an auxiliary routine called by PZGEHRD. In the following comments sub( A ) denotes A(IA:IA+N-1,JA:JA+N-1). ARGUMENTS
N (global input) INTEGER The number of rows and columns to be operated on, i.e. the order of the distributed submatrix sub( A ). N >= 0. K (global input) INTEGER The offset for the reduction. Elements below the k-th subdiagonal in the first NB columns are reduced to zero. NB (global input) INTEGER The number of columns to be reduced. A (local input/local output) COMPLEX*16 pointer into the local memory to an array of dimension (LLD_A, LOCc(JA+N-K)). On entry, this array contains the the local pieces of the N-by-(N- K+1) general distributed matrix A(IA:IA+N-1,JA:JA+N-K). On exit, the elements on and above the k-th subdiagonal in the first NB columns are overwritten with the corresponding elements of the reduced distributed matrix; the elements below the k-th subdiagonal, with the array TAU, represent the matrix Q as a product of elementary reflectors. The other columns of A(IA:IA+N-1,JA:JA+N-K) are unchanged. See Further Details. IA (global input) INTEGER The row index in the global array A indicating the first row of sub( A ). JA (global input) INTEGER The column index in the global array A indicating the first column of sub( A ). DESCA (global and local input) INTEGER array of dimension DLEN_. The array descriptor for the distributed matrix A. TAU (local output) COMPLEX*16 array, dimension LOCc(JA+N-2) The scalar factors of the elementary reflectors (see Further Details). TAU is tied to the distributed matrix A. T (local output) COMPLEX*16 array, dimension (NB_A,NB_A) The upper triangular matrix T. Y (local output) COMPLEX*16 pointer into the local memory to an array of dimension (LLD_Y,NB_A). On exit, this array contains the local pieces of the N-by-NB distributed matrix Y. LLD_Y >= LOCr(IA+N-1). IY (global input) INTEGER The row index in the global array Y indicating the first row of sub( Y ). JY (global input) INTEGER The column index in the global array Y indicating the first column of sub( Y ). DESCY (global and local input) INTEGER array of dimension DLEN_. The array descriptor for the distributed matrix Y. WORK (local workspace) COMPLEX*16 array, dimension (NB) FURTHER DETAILS
The matrix Q is represented as a product of nb elementary reflectors Q = H(1) H(2) . . . H(nb). Each H(i) has the form H(i) = I - tau * v * v' where tau is a complex scalar, and v is a complex vector with v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in A(ia+i+k:ia+n-1,ja+i-1), and tau in TAU(ja+i-1). The elements of the vectors v together form the (n-k+1)-by-nb matrix V which is needed, with T and Y, to apply the transformation to the unreduced part of the matrix, using an update of the form: A(ia:ia+n-1,ja:ja+n-k) := (I-V*T*V')*(A(ia:ia+n-1,ja:ja+n-k)-Y*V'). The contents of A(ia:ia+n-1,ja:ja+n-k) on exit are illustrated by the following example with n = 7, k = 3 and nb = 2: ( a h a a a ) ( a h a a a ) ( a h a a a ) ( h h a a a ) ( v1 h a a a ) ( v1 v2 a a a ) ( v1 v2 a a a ) where a denotes an element of the original matrix A(ia:ia+n-1,ja:ja+n-k), h denotes a modified element of the upper Hessenberg matrix H, and vi denotes an element of the vector defining H(i). LAPACK version 1.5 12 May 1997 PZLAHRD(l)
All times are GMT -4. The time now is 06:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy