0

I have data that follows a similar format to

Name,Fruit.

The goal is to create an adjacency matrix that demonstrates the relationships between the different names. If two names are related, 1 is inputed into the corresponding cell in the adjacency matrix. If not, 0 is inputed. Two names are related if both names have the same fruit. For instance, since Jake has Apple and Carly has Apple, they are both related. Here is a sample adjacency matrix based on the sample data provided.

Name x Name.

What is the most efficient method of doing this in R programming when I have over 600,000 rows of data? Any suggestions?

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • How many names N and fruit F do you have? What is your current code and its runtime? Why is runtime an issue? I presume for efficiency you treat names and fruits as categorical, not strings. – smci Aug 05 '21 at 21:31

1 Answers1

1

Try the following code with igraph

library(igraph)
get.adjacency(graph_from_data_frame(df,directed = FALSE),sparse = FALSE)
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • @ThomaslsCoding how we can modify this code and use it for a data frame with more than one column and see the relation between all the columns? – Jina Feb 02 '23 at 11:23