> N <- letters[1:8]
> u <- c(1,1,1,2,2,2,3,3,3,4,4,5,5,6,6,7)
> v <- c(2,3,4,4,5,7,4,6,8,5,6,7,8,7,8,8)
> w <- c(2,1,3,1,5,6,3,5,4,3,2,2,4,7,1,3)
> info <- list(network="GcoresTest",title="GenCores test",
+ by="Vladimir Batagelj",date=date())
> ways <- list(U="first node",V="second node",w="weight")
> nodes <- list(U=data.frame(ID=N),V=data.frame(ID=N))
> links <- data.frame(U=c(u,v),V=c(v,u),w=c(w,w))
> data <- list()
> G <- list(format="MWnets",info=info,ways=ways,nodes=nodes,links=links,data=data)
> str(G)
> write(toJSON(G),"GcoresTest.json")
> n <- 21; N <- letters[1:n]
> u <- c(1,1,1,2,2,3,3, 4, 4,5,5,6,6,6, 9, 9, 9,10,10,11,11,11,13,13,16,17,17,18,19)
> v <- c(2,3,4,3,4,4,5,11,13,6,9,7,8,9,10,11,12,11,12,13,14,12,14,15,17,18,19,20,20)
> w <- rep(1,2*length(u))
> info <- list(network="coresTest",
+ title="Fast algorithms for determining (generalized) core groups in social networks, ADAC (2011) 5:129–145",
+ by=c("Vladimir Batagelj","Matjaž Zaveršnik"),
+ url="https://link.springer.com/article/10.1007/s11634-010-0079-y",
+ creator="Vladimir Batagelj",date=date())
> ways <- list(U="first node",V="second node",w="weight")
> nodes <- list(U=data.frame(ID=N),V=data.frame(ID=N))
> links <- data.frame(U=c(u,v),V=c(v,u),w=w)
> data <- list()
> Net <- list(format="MWnets",info=info,ways=ways,nodes=nodes,links=links,data=data)
> str(Net)
List of 6
$ format: chr "MWnets"
$ info :List of 6
..$ network: chr "coresTest"
..$ title : chr "Fast algorithms for determining (generalized) core groups in social networks, ADAC (2011) 5:129–145"
..$ by : chr [1:2] "Vladimir Batagelj" "Matjaž Zaveršnik"
..$ url : chr "https://link.springer.com/article/10.1007/s11634-010-0079-y"
..$ creator: chr "Vladimir Batagelj"
..$ date : chr "Wed Jan 25 01:52:05 2023"
$ ways :List of 3
..$ U: chr "first node"
..$ V: chr "second node"
..$ w: chr "weight"
$ nodes :List of 2
..$ U:'data.frame': 21 obs. of 1 variable:
.. ..$ ID: chr [1:21] "a" "b" "c" "d" ...
..$ V:'data.frame': 21 obs. of 1 variable:
.. ..$ ID: chr [1:21] "a" "b" "c" "d" ...
$ links :'data.frame': 58 obs. of 3 variables:
..$ U: num [1:58] 1 1 1 2 2 3 3 4 4 5 ...
..$ V: num [1:58] 2 3 4 3 4 4 5 11 13 6 ...
..$ w: num [1:58] 1 1 1 1 1 1 1 1 1 1 ...
$ data : list()
> write(toJSON(Net),"coresTest.json")
Analysis
> n1 <- 6; n2 <- 8; N1 <- letters[1:n1]; N2 <- toupper(letters[1:n2])
> u <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,6,6)
> v <- c(3,2,5,1,8,2,5,1,8,7,5,1,8,4,7,8,4,7,6,2,4,7,6,5,4)
> w <- rep(1,length(u))
> info <- list(network="TwoModeTest",title="Two-mode network example",
+ by="Vladimir Batagelj",date=date())
> ways <- list(U="first mode",V="second mode",w="weight")
> nodes <- list(U=data.frame(ID=N1),V=data.frame(ID=N2))
> links <- data.frame(U=u,V=v,w=w)
> data <- list()
> TM <- list(format="MWnets",info=info,ways=ways,nodes=nodes,links=links,data=data)
> str(TM)
List of 6
$ format: chr "MWnets"
$ info :List of 4
..$ network: chr "TwoModeTest"
..$ title : chr "Two-mode network example"
..$ by : chr "Vladimir Batagelj"
..$ date : chr "Mon Jan 23 02:42:36 2023"
$ ways :List of 3
..$ U: chr "first mode"
..$ V: chr "second mode"
..$ w: chr "weight"
$ nodes :List of 2
..$ U:'data.frame': 6 obs. of 1 variable:
.. ..$ ID: chr [1:6] "a" "b" "c" "d" ...
..$ V:'data.frame': 8 obs. of 1 variable:
.. ..$ ID: chr [1:8] "A" "B" "C" "D" ...
$ links :'data.frame': 25 obs. of 3 variables:
..$ U: num [1:25] 1 1 1 1 1 2 2 2 2 2 ...
..$ V: num [1:25] 3 2 5 1 8 2 5 1 8 7 ...
..$ w: num [1:25] 1 1 1 1 1 1 1 1 1 1 ...
$ data : list()
> write(toJSON(TM),"TwoModeTest.json")