Thanks, but I have more than two node characteristics, plus I need the links between "A" nodes. Although simple, I think it solves it for this case:
Mcol <- outer(y, x, "==") Mcol[] <- as.integer(Mcol) Mfil <- outer(x, y, "==") Mfil[] <- as.integer(Mfil) M=Mcol + Mfil M= replace(M, M == 2, 1) Thanks for the help. -------- *Sebastián Goinheix*Instituto de Economía - UdelaR Tel: 24001369 (int. 116) *Por favor, evite imprimir este correo.* 2016-12-28 0:21 GMT-03:00 George Vega Yon <[email protected]>: > So this reproduces the table that you need, but from what you are > describing I'm not sure whether this is what you want. > > Best, > > rm(list=ls()) > > x <- c("A", "A", "B", "B", "B") > > # An entry in mat will be 1 iff x_i != x_j > M <- outer(x, x, "!=") > M[] <- as.integer(M) > diag(M) <- 0 > > dimnames(M) <- list(x,x) > M > > # A nicer way of printing it > library(Matrix) > methods::as(M, "dgCMatrix") > > > methods::as(M, "dgCMatrix") > 5 x 5 sparse Matrix of class "dgCMatrix" > A A B B B > A . . 1 1 1 > A . . 1 1 1 > B 1 1 . . . > B 1 1 . . . > B 1 1 . . . > > > George G. Vega Yon > +1 (626) 381 8171 <(626)%20381-8171> > http://cana.usc.edu/vegayon > > On Tue, Dec 27, 2016 at 7:07 PM, Sebastián Goinheix <[email protected]> > wrote: > >> Hi: >> I need a simmetric matrix. >> Mcol <- outer(y, x, "==") >> Mcol[] <- as.integer(Mcol) >> Mrow <- outer(x, y, "==") >> Mrow[] <- as.integer(Mrow) >> >> Could I combine rows and columns or I need another different approach? >> Thanks >> >> >> -------- >> >> *Sebastián Goinheix*Instituto de Economía - UdelaR >> Tel: 24001369 (int. 116) >> *Por favor, evite imprimir este correo.* >> >> 2016-12-27 17:32 GMT-03:00 Sebastián Goinheix <[email protected]>: >> >>> Thank you, i'll try in this way >>> >>> >>> -------- >>> >>> *Sebastián Goinheix*Instituto de Economía - UdelaR >>> Tel: 24001369 (int. 116) >>> *Por favor, evite imprimir este correo.* >>> >>> 2016-12-27 16:52 GMT-03:00 George Vega Yon <[email protected]>: >>> >>>> Let M={m_ij} be a square matrix of size n, then m_ij = 1 iff x_j="A" >>>> and i != j. If you want to build something like that, then this should >>>> work: >>>> >>>> rm(list=ls()) >>>> >>>> x <- c("A", "A", "B", "B", "A") >>>> y <- rep("A", length(x)) >>>> >>>> # An entry in mat will be 1 iff target == "A" >>>> M <- outer(y, x, "==") >>>> M[] <- as.integer(M) >>>> diag(M) <- 0 >>>> >>>> dimnames(M) <- list(x,x) >>>> M >>>> >>>> # A nicer way of printing it >>>> library(Matrix) >>>> methods::as(M, "dgCMatrix") >>>> >>>> > methods::as(M, "dgCMatrix") >>>> 5 x 5 sparse Matrix of class "dgCMatrix" >>>> A A B B A >>>> A . 1 . . 1 >>>> A 1 . . . 1 >>>> B 1 1 . . 1 >>>> B 1 1 . . 1 >>>> A 1 1 . . . >>>> >>>> >>>> Best, >>>> >>>> George G. Vega Yon >>>> +1 (626) 381 8171 <(626)%20381-8171> >>>> http://cana.usc.edu/vegayon >>>> >>>> On Tue, Dec 27, 2016 at 11:41 AM, Sebastián Goinheix < >>>> [email protected]> wrote: >>>> >>>>> Hi: >>>>> I tried the outer function but I couldn't fix it. >>>>> The solution you suggest is another way of generate homophilia >>>>> matrices (linking vertices with equal characteristics). Actually what I >>>>> need is to generate links between all the nodes and those that have a >>>>> specific attribute, as: >>>>> A A B B B >>>>> A 0 1 1 1 1 >>>>> A 1 0 1 1 1 >>>>> B 1 1 0 0 0 >>>>> B 1 1 0 0 0 >>>>> B 1 1 0 0 0 >>>>> >>>>> Any ideas? >>>>> thank you very much! >>>>> >>>>> >>>>> -------- >>>>> >>>>> *Sebastián Goinheix*Instituto de Economía - UdelaR >>>>> Tel: 24001369 (int. 116) >>>>> *Por favor, evite imprimir este correo.* >>>>> >>>>> 2016-12-21 23:24 GMT-03:00 Sebastián Goinheix <[email protected]>: >>>>> >>>>>> Thanks George >>>>>> >>>>>> >>>>>> -------- >>>>>> >>>>>> *Sebastián Goinheix*Instituto de Economía - UdelaR >>>>>> Tel: 24001369 (int. 116) >>>>>> *Por favor, evite imprimir este correo.* >>>>>> >>>>>> 2016-12-21 16:33 GMT-03:00 George Vega Yon <[email protected]>: >>>>>> >>>>>>> Does this works? >>>>>>> >>>>>>> rm(list=ls()) >>>>>>> >>>>>>> x <- c("A", "A", "B", "B", "B") >>>>>>> mat <- outer(x, x, "==") >>>>>>> mat[] <- as.integer(mat) >>>>>>> >>>>>>> dimnames(mat) <- list(x,x) >>>>>>> mat >>>>>>> >>>>>>> > mat >>>>>>> A A B B B >>>>>>> A 1 1 0 0 0 >>>>>>> A 1 1 0 0 0 >>>>>>> B 0 0 1 1 1 >>>>>>> B 0 0 1 1 1 >>>>>>> B 0 0 1 1 1 >>>>>>> >>>>>>> Best, >>>>>>> >>>>>>> George G. Vega Yon >>>>>>> +1 (626) 381 8171 <(626)%20381-8171> >>>>>>> http://cana.usc.edu/vegayon >>>>>>> >>>>>>> On Wed, Dec 21, 2016 at 9:21 AM, Sebastián Goinheix < >>>>>>> [email protected]> wrote: >>>>>>> >>>>>>>> Hi, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I want to perform network regresion with QAP procedure (netlm >>>>>>>> function of sna package). >>>>>>>> I have matrices with some inter-organizational relations, and >>>>>>>> with calculated matrices for homophily hypotheses through the >>>>>>>> bipartite.projection function. >>>>>>>> But now I need a matrix that contains links from all nodes to >>>>>>>> those that have a specific attribute, say "A". For example: >>>>>>>> >>>>>>>> nodes attributes >>>>>>>> 1 A >>>>>>>> 2 A >>>>>>>> 3 B >>>>>>>> 4 B >>>>>>>> 5 B >>>>>>>> >>>>>>>> Therefore, the resulting adjacency matrix will be: >>>>>>>> >>>>>>>> 1 2 3 4 5 >>>>>>>> 1 0 1 1 1 1 >>>>>>>> 2 1 0 1 1 1 >>>>>>>> 3 1 1 0 0 0 >>>>>>>> 4 1 1 0 0 0 >>>>>>>> 5 1 1 0 0 0 >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I assume the sample_pa function will not work since the network is >>>>>>>> based on vertex attributes >>>>>>>> and >>>>>>>> the model should not be random >>>>>>>> . >>>>>>>> >>>>>>>> How can I get it in Igraph (or other)? >>>>>>>> Thanks >>>>>>>> >>>>>>>> >>>>>>>> -------- >>>>>>>> >>>>>>>> *Sebastián Goinheix*Instituto de Economía - UdelaR >>>>>>>> Tel: 24001369 (int. 116) >>>>>>>> *Por favor, evite imprimir este correo.* >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> igraph-help mailing list >>>>>>>> [email protected] >>>>>>>> https://lists.nongnu.org/mailman/listinfo/igraph-help >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> igraph-help mailing list >>>>>>> [email protected] >>>>>>> https://lists.nongnu.org/mailman/listinfo/igraph-help >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> igraph-help mailing list >>>>> [email protected] >>>>> https://lists.nongnu.org/mailman/listinfo/igraph-help >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> igraph-help mailing list >>>> [email protected] >>>> https://lists.nongnu.org/mailman/listinfo/igraph-help >>>> >>>> >>> >> >> _______________________________________________ >> igraph-help mailing list >> [email protected] >> https://lists.nongnu.org/mailman/listinfo/igraph-help >> >> > > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help > >
_______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
