My goal is to develop a network visualization in R, starting from a "classic" data frame. I thus have to create two files: nodes and links. My current data set looks like this:
Driver Insurance_taker Counterparty1 Counterparty2 Counterparty3 Counterparty4 Counterparty5
Allan Steven NA Patrick Oliver Jean William
Ana Anastasia Max Pierre Jack Sam NA
Sample data (Please note that there are multiple NAs in the data):
mydata <- data.table(Driver=c("Allan", "Ana"),
Insurance_taker = c("Steven", "Anastasia"),
Counterparty1= c(NA, "Max"),
Counterparty2= c("Patrick", "Pierre"),
Counterparty3= c("Olivier", "Jack"),
Counterparty4= c("Jean", "Sam"),
Counterparty5= c("William",NA))
My goal is to have one file called "nodes.csv" like:
Names Type
Allan Driver
Ana Driver
Steven Insurance_taker
Anastasia Insurance_taker
... ...
I have managed to get this file, but I also want to create another file (called "links" let's say) that would look like this:
From To Weight Type
Patrick Allan 30 witness1_driver
Allan Steven 20 car_driver
.... ... ... ....
The weights will be determine according to the relationship type (eg witness1_driver => weight = 30) Any help would be really much appreciated.
Thanks a lot!! :)