Hi
I would like to create an incidence matrix.
I have a file with 3 columns, like:
id x y
A 22 2
B 4 21
C 21 360
D 26 2
E 22 58
F 2 347
And I want a matrix like (without col and row names):
2 4 21 22 26 58 347 360
A 1 0 0 1 0 0 0 0
B 0 1 1 0 0 0 0 0
C 0 0 1 0 0 0 0 1
D 1 0 0 0 1 0 0 0
E 0 0 0 1 0 1 0 0
F 1 0 0 0 0 0 1 0
I have started the code like:
haps = readdlm("File.txt",header=true) #read the file
hap1_2 = map(Int64,haps[1][:,2:end]) # create a subfile with 2 and
3 column
ID = (haps[1][:,1]) #subfile with
the 1 column
dic1 = Dict()
for (i in 1:21)
dic1[ID[i]] = hap1_2[i,:]
end
X=[zeros(21,22)]; #the original file has 21 rows
and 22 columns
hcat(ID,X)
The problem now is that I don't know how to fill the matrix with 1s in the
specific columns as in the example above.
I'm also not sure if I'm on the right way.
Any suggestion??
Thanks!