This is a simple R task. I have a list of some people with IDs and a list of friends of each of the people (with IDs too). They are here:
> dput(friends_of_people)
structure(list(`7614` = c(1091, 1252, 1827, 34687), `29752` = c(1419,
1799, 3353, 4665), `33220` = c(143, 297, 436, 52078), `34687` = c(14,
17, 34, 70, 161, 7614), `52078` = c(58, 66, 99, 184, 33220)), .Names = c("7614",
"29752", "33220", "34687", "52078"))
> dput(people)
c(7614L, 29752L, 33220L, 34687L, 52078L)
I want to extract friend relations from these lists to construct a friends network. For this, I need to create a NxN matrix, where N - the number of people, and 0 in a cell (i,j) means that person i is not a friend of person j, and vice versa (cell j, i, in this case, contains 0 too). If they are friends (there is the ID of person i in the list of friends of person j and vice versa), the cell would contain 1. The final result ought to look like this:
> result
7614 29752 33220 34687 52078
7614 0 0 0 1 0
29752 0 0 0 0 0
33220 0 0 0 0 1
34687 1 0 0 0 0
52078 0 0 1 0 0
Note that the number of nodes is several thousand in the real task, and a number of friends for each person is also several thousand, so I am worried about the performance. I know this can be an easy task, but don't know where to start. Would appreciate any help.
You could also try