Thank you so much! I hate when the answer is so obvious that makes me feel dumb.
• 0 views
•
link
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?
> 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
Thank you so much! I hate when the answer is so obvious that makes me feel dumb.
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
Log in to answer this question.