I'm trying to cluster a graph dataset using Markov Clustering Algorithm in R. I've followed thorugh so many tutorials including
My dataset looks like this:
V1 V2 V3
1 0 1 1
2 0 2 1
3 1 2 1
4 2 3 2
5 2 4 2
6 2 5 3
7 3 6 4
8 3 7 5
9 3 8 5
10 4 9 6
11 4 10 4
12 4 11 5
13 4 12 7
14 4 13 4
V1 and V2 are nodes and V3 is weight of the connection.
Every tutorial mentions creating an adjacent matrix. When I try their code, it always throws out of bound errors. I'm assuming this is due to different parameters for columns and rows. But nothing really makes sense.
Even creating a Adjacent matrix is challenging, let alone implementing MCL.
Any ideas? What am I missing here?
UPDATE:
Here's the code I'm trying:
df <- read.table(header=T, stringsAsFactors=F, text=" V1 V2 V3
1 0 1 1
2 0 2 1
3 1 2 1
4 2 3 2
5 2 4 2
6 2 5 3
7 3 6 4
8 3 7 5
9 3 8 5
10 4 9 6
11 4 10 4
12 4 11 5
13 4 12 7
14 4 13 4")
include library reshape2:
require(reshape2)
Now using reshape to convert it to adjacent table:
m <- as.matrix(dcast(df, V1 ~ V2, value.var = "V3", fill=0))
I'm following this tutorial. But at the end of
m <- as.matrix(dcast(df, V1 ~ V2, value.var = "V3", fill=0)),
there is another parameter [,2:3]
in the tutorial. The tutorial uses square matrix to begin with. When I try to run the next command:
row.names(m) <- colnames(m)
it throws errors showing:
Error in dimnames(x) <- dn :
length of 'dimnames' [1] not equal to array extent