r - How to construct a network from a file of edges -


i have following file:

apple   pear  apple   raspberry  raspberry   pear  lemon   pear  lime    plum  pineapple   grape 

as output, i'd list of chains of fruits--on each line, associate 2 fruits ever appear on line, e.g., 1 line pineapple, grape because each appears once , once, together.

i'm looking following output:

apple pear raspberry lemon  lime plum  pineapple grape 

does have suggestions?

thank you!

it seems you're after creating network of fruits, you're best off using network package (which learned in answering question, it's got sorts of functionality don't understand yet).

to read text, use read.table(text=...):

x<-read.table(text="apple   pear  apple   raspberry  raspberry   pear  lemon   pear  lime    plum  pineapple   grape") 

then create network object x:

library(network) net<-network(x) 

for example, can plot network:

plot(net) 

network (unlabelled)

haven't quite figured out how exact desired output, can see in plot above we've achieved association wanted. not sure end goal, check out tutorials network.


Comments