Filling expr matrix for igraph
2
0
Entering edit mode
7.0 years ago
Spacebio ▴ 200

Hello,

I have a file containing 11300 genes, looking like this:

A   active      B
B   inactive    C
C   unknown     E
D   active      D
E   inactive    A
A   active      C
B   unknown     A
C   inactive    D
D   active      E
E   active      B

After I stack the genes, I get a matrix like this:

A   active
B   inactive
C   unknown
D   active
E   inactive
A   active
B   unknown
C   inactive
D   active
E   active
B   active
C   inactive
E   unknown
D   active
A   inactive
C   active
A   unknown
D   inactive
E   active
B   active

Then, I remove the duplicates and I get the following output:

A   active
B   inactive
C   unknown
D   active
E   inactive
B   unknown
C   inactive
E   active
B   active
E   unknown
A   inactive
C   active
A   unknown
D   inactive

After that, I would like to have a matrix like this:

    Active  Inactive    Unknown
A      1        1          1
B      1        1          1
C      1        1          1
D      1        1          0
E      1        1          1

I tried with the followong syntax:

m <- matrix(nrow = 1467, ncol = 4)
for(column in 1){
  m[, column] <- nodes$values
}

But with that I just construct the matrix without filling it. The 1467 is the total number of uniquegenes in my file. Can someone help me?

R igraph matrix • 1.5k views
ADD COMMENT
3
Entering edit mode
7.0 years ago
Michael 55k
> bla
   V1       V4
1   A   active
2   B inactive
3   C  unknown
4   D   active
5   E inactive
6   B  unknown
7   C inactive
8   E   active
9   B   active
10  E  unknown
11  A inactive
12  C   active
13  A  unknown
14  D inactive
> table(bla)
   V4
V1  active inactive unknown
  A      1        1       1
  B      1        1       1
  C      1        1       1
  D      1        1       0
  E      1        1       1
ADD COMMENT
0
Entering edit mode

Thank you so much! I hate when the answer is so obvious that makes me feel dumb.

ADD REPLY
1
Entering edit mode
7.0 years ago

with datamash:

$ datamash crosstab 1,2 --filler 0 < file.txt 
    active  inactive    unknown
A   1   1   1
B   1   1   1
C   1   1   1
D   1   1   0
E   1   1   1

input:

$ cat file.txt 
A   active
B   inactive
C   unknown
D   active
E   inactive
B   unknown
C   inactive
E   active
B   active
E   unknown
A   inactive
C   active
A   unknown
D   inactive
ADD COMMENT

Login before adding your answer.

Traffic: 1811 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6