This is not an igraph issue, I believe. You need to go over your indices and update the matrix, i.e.
for (i in seq_along(t.list)) { temp[t.list[i], c.list[i]] <- temp[t.list[i], c.list[i]] + 1 } Best, Gabor On Tue, Aug 2, 2011 at 4:50 PM, Robinson, David G <dro...@sandia.gov> wrote: > I realize that matrix indexing has been addressed in various flavors, but I'm > stumped and didn't find anything in the archives. It's not clear if it is an > igraph issue or a more general problem. Thanks in advance for your patience. > > I am using igraph to read a gml file > (http://www-personal.umich.edu/~mejn/netdata/football.zip > ). The gml file contains vertex attributes (conference and team) that are > provided as character/integer values. > > I would like to build a matrix of dimension (length.team, length.conference) > where the elements are zero except for 1's at the location of index [team, > conference]. > > Here is a snippet of code that hopefully captures what I am trying to do: > > original<-read.graph("./Data/football/football.gml", format="gml") > conf.list<- get.vertex.attribute(original, 'value', index=V(original))+1 > team.list<- get.vertex.attribute(original, 'id', index=V(original))+1 > temp<- matrix(0,115,12) > temp[team.list, conf.list]<-1 > > Unfortunately, temp[] is filled with 1's. > > However, if I try: > c.list=c(1,3,5) > t.list=c(2,4,6) > temp[t.list,c.list]<-1 > > then things work as I would expect. FWIW - I have tried > as.integer(get.vertex.attribute(...)) with no luck. > > Thanks for any suggestions. > > > > > ***************************************************** >> original<-read.graph("./Data/football/football.gml", format="gml") >> conf.list<- get.vertex.attribute(original, 'value', index=V(original))+1 >> team.list<- get.vertex.attribute(original, 'id', index=V(original))+1 >> conf.list > [1] 8 1 3 4 8 4 3 9 9 8 4 11 7 3 7 3 8 10 7 2 10 9 9 8 > 11 1 7 10 12 2 2 7 3 1 7 2 6 > [38] 1 7 3 4 8 6 7 5 1 12 3 5 12 11 9 4 12 7 2 10 5 12 11 3 > 7 10 11 3 10 5 12 9 11 10 7 4 12 > [75] 4 5 10 9 9 2 6 4 6 12 4 7 5 10 12 1 6 5 5 8 2 10 10 11 > 4 7 3 2 4 1 8 1 3 4 9 1 5 > [112] 9 5 10 12 >> team.list > [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 > 19 20 21 22 23 24 25 26 27 > [28] 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 > 46 47 48 49 50 51 52 53 54 > [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 > 73 74 75 76 77 78 79 80 81 > [82] 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 > 100 101 102 103 104 105 106 107 108 > [109] 109 110 111 112 113 114 115 >> length(conf.list) > [1] 115 >> length(team.list) > [1] 115 >> temp<- matrix(0,115,12) >> r<-c(1,3,5) >> col<- c(2,4,6) >> temp[r,col]<-1 >> temp[1:10,] > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] > [1,] 0 1 0 1 0 1 0 0 0 0 0 0 > [2,] 0 0 0 0 0 0 0 0 0 0 0 0 > [3,] 0 1 0 1 0 1 0 0 0 0 0 0 > [4,] 0 0 0 0 0 0 0 0 0 0 0 0 > [5,] 0 1 0 1 0 1 0 0 0 0 0 0 > [6,] 0 0 0 0 0 0 0 0 0 0 0 0 > [7,] 0 0 0 0 0 0 0 0 0 0 0 0 > [8,] 0 0 0 0 0 0 0 0 0 0 0 0 > [9,] 0 0 0 0 0 0 0 0 0 0 0 0 > [10,] 0 0 0 0 0 0 0 0 0 0 0 0 >> temp[team.list,conf.list]<- 1 >> temp[1:10,] > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] > [1,] 1 1 1 1 1 1 1 1 1 1 1 1 > [2,] 1 1 1 1 1 1 1 1 1 1 1 1 > [3,] 1 1 1 1 1 1 1 1 1 1 1 1 > [4,] 1 1 1 1 1 1 1 1 1 1 1 1 > [5,] 1 1 1 1 1 1 1 1 1 1 1 1 > [6,] 1 1 1 1 1 1 1 1 1 1 1 1 > [7,] 1 1 1 1 1 1 1 1 1 1 1 1 > [8,] 1 1 1 1 1 1 1 1 1 1 1 1 > [9,] 1 1 1 1 1 1 1 1 1 1 1 1 > [10,] 1 1 1 1 1 1 1 1 1 1 1 1 >> >> --------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Gabor Csardi <csa...@rmki.kfki.hu> MTA KFKI RMKI ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.