0

I was following this Building Adjacency matrix from DF

I have this df as toy example :

lf3 = structure(list(session_id = c(1L, 1L, 1L, 2L, 3L, 5L, 5L, 6L, 
6L, 7L), userId = c(1, 1, 1, 2, 2, 4, 4, 5, 5, 5), datetime = 
structure(c(1457029336, 
1457029337, 1457029340, 1457029596, 1457313569, 1457030783, 1457030784, 
1457030918, 1457030920, 1457370365), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), referer = c(22, 2, 7, 5, 23, 20, 7, 24, 18, 
22), request = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 5)), .Names = c("session_id", 
"userId", "datetime", "referer", "request"), row.names = c(NA, 
10L), class = "data.frame")

I tried this piece of code :

lf3 %>% 
mutate_at(vars(referer,request),funs(factor(., levels))) %>% 
group_by(referer, request) %>%
tally() %>%
spread(request, n, drop=FALSE, fill=0)

But its giving some error

Error in mutate_impl(.data, dots) : 'match' requires vector arguments

So i tried this :

lf3 %>% 
mutate_at(vars(referer,request),funs(factor(.))) %>% 
group_by(referer, request) %>%
tally() %>%
spread(request, n, drop=FALSE, fill=0)

But cant make a network graph using igraph library as it gives n*n+1 dimensions 1 extra column for referer being added .so graph.adjacency() not working .How to remove that referer extra column

SumitArya
  • 111
  • 5
  • which two columns you want to build adjacency matrix from? can you please specify – Hardik Gupta Oct 10 '17 at 05:01
  • You dont even need an adjacency matrix to build an igraph object, you can do it directly from edge pairs. `graph_from_edgelist(as.matrix(lf3[,c("referer","request")]))` or whichever two columns you want. – Spacedman Oct 10 '17 at 06:45
  • @Spacedman ok thats interesting..and if i want to var request as vertex and draw a graph using these generated edges – SumitArya Oct 10 '17 at 07:04
  • @Spacedman i managed to plot this graph but how to display edge weights as freq. of referer->request – SumitArya Oct 10 '17 at 07:11
  • Explain all that in your question. We can't tell what your code is doing, especially when it fails. Describe your problem precisely. I suspect its just a case of counting duplicate rows and setting an edge weight, but your initial question says nothing about edge weights at all. – Spacedman Oct 10 '17 at 09:01

0 Answers0