1

I don't know why I can't use R script for igraph any more that worked before. I would really appreciate it if you could help me with this. The script I used here is:

library(igraph)

matrix1<-as.matrix(data)

matrix1

     var1 var2 var3 var4 var5 var6 var7 var8
[1,] 1.00 0.04 0.21 0.39 0.06 0.37 0.03 0.44
[2,] 0.04 1.00 0.34 0.36 0.63 0.25 0.66 0.18
[3,] 0.21 0.34 1.00 0.44 0.41 0.57 0.72 0.62
[4,] 0.39 0.36 0.44 1.00 0.28 0.14 0.51 0.10
[5,] 0.06 0.63 0.41 0.28 1.00 0.50 0.73 0.39
[6,] 0.37 0.25 0.57 0.14 0.50 1.00 0.50 0.65
[7,] 0.03 0.66 0.72 0.51 0.73 0.50 1.00 0.52
[8,] 0.44 0.18 0.62 0.10 0.39 0.65 0.50 1.00

graph.adjacency(matrix1,mode='undirected',weighted=TRUE)

"then I get error message below"

Error in d[i, ] : incorrect number of dimensions Warning: stack imbalance in '.Call', 51 then 50

More information below:

> str(matrix1)
 num [1:8, 1:8] 1 0.04 0.21 0.39 0.06 0.37 0.03 0.44 0.04 1 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:8] "var1" "var2" "var3" "var4" ...

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] igraph_0.6.5-2

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0    digest_0.6.3       ggplot2_0.9.3.1   
 [5] grid_3.0.2         gtable_0.1.2       labeling_0.2       lattice_0.20-23   
 [9] MASS_7.3-29        Matrix_1.0-14      mgcv_1.7-26        munsell_0.4.2     
[13] nlme_3.1-111       plyr_1.8           proto_0.3-10       RColorBrewer_1.0-5
[17] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_3.0.2    

> traceback()
4: c(list(), list(logical(0)))
3: .Call("R_igraph_weighted_adjacency", adjmatrix, as.numeric(mode), 
       weighted, diag, PACKAGE = "igraph")
2: graph.adjacency.dense(adjmatrix, mode = mode, weighted = weighted, 
       diag = diag)
1: graph.adjacency(matrix1, mode = "undirected", weighted = TRUE)

Thanks!

Young
  • 47
  • 2
  • 9
  • My guess is that you make a mistake when you construct the 'matrix1' matrix, or 'data'. Please include that code as well. – Gabor Csardi Oct 02 '13 at 13:18
  • @GaborCsardi Thanks for your comment. I used the correlation table as shown above. That is the matrix I used. What am I doing wrong here?? – Young Oct 03 '13 at 01:56
  • Again, we don't see your code. I get that this is your matrix, but that is not a substitute for the code that creates it. Maybe there is something in the matrix object that we don't see here. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Gabor Csardi Oct 03 '13 at 13:16

2 Answers2

1

The following works fine for me with igraph 0.6.5-2, R 3.0.1, OSX Lion, so please include some self contained code that reproduces your problem, also your igraph and R version and platform. Thanks.

matrix1 <- as.matrix(read.table(header=TRUE, textConnection("
 var1 var2 var3 var4 var5 var6 var7 var8
 1.00 0.04 0.21 0.39 0.06 0.37 0.03 0.44
 0.04 1.00 0.34 0.36 0.63 0.25 0.66 0.18
 0.21 0.34 1.00 0.44 0.41 0.57 0.72 0.62
 0.39 0.36 0.44 1.00 0.28 0.14 0.51 0.10
 0.06 0.63 0.41 0.28 1.00 0.50 0.73 0.39
 0.37 0.25 0.57 0.14 0.50 1.00 0.50 0.65
 0.03 0.66 0.72 0.51 0.73 0.50 1.00 0.52
 0.44 0.18 0.62 0.10 0.39 0.65 0.50 1.00
")))

graph.adjacency(matrix1, mode='undirected', weighted=TRUE)
# IGRAPH UNW- 8 36 -- 
# + attr: name (v/c), weight (e/n)
Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • I used your script above. But didn't work. I still get the same error message. I also used this script to copy and paste the table: data<-read.delim("clipboard").But didn't work either. I use R-3.0.2 and igraph0.6.5-2 Windows7. Thanks. – Young Oct 06 '13 at 23:42
  • I don't understand why you would use `read.delim`. Just copy and paste the code into R. I suspect that you create a non-square matrix that has more rows than columns, because you put the header line into the matrix. You can run `dim(matrix1)` to check the dimensions of your matrix. It must be a square matrix for an adjacency matrix. Btw. I tried the code on Windows and works fine as well. – Gabor Csardi Oct 08 '13 at 16:06
  • dim(matrix1) gave me this: [1] 8 8. Columns and rows have the same number. I still get "Error in d[i, ] : incorrect number of dimensions Warning: stack imbalance in '.Call', 49 then 48".... Why???? – Young Oct 14 '13 at 07:13
  • I wish I knew. I still cannot reproduce this. What does `str(matrix1)` say? What is the output of your `sessionInfo()`, right after the error? – Gabor Csardi Oct 14 '13 at 19:18
  • I am sorry, but this is not really readable, please add it to your question. Thanks. – Gabor Csardi Oct 15 '13 at 22:57
  • Thanks, nothing, still. :( My last hope: can you please send me the output of `traceback()`, right after the error happens? Thanks. – Gabor Csardi Oct 16 '13 at 13:58
-1

I needed to remove all objects.

Type in rm(list=ls()).

Then, the R scripts I used above should work.

Young
  • 47
  • 2
  • 9