How to create pairs from a single column based on order of occurrence in R? -


i have dataset follows:

timestamp,session,event 5/23/2016 13:00,1,a 5/23/2016 13:20,1,b 5/23/2016 13:40,1,c 5/23/2016 14:00,2,b 5/23/2016 15:00,2,c 5/23/2016 15:20,3,b 5/23/2016 15:40,3,c 5/23/2016 16:00,3,d 

i trying build ordered pairs of events within session sorted timestamp. objective build data input sankey charts needs following format:

start,end,value a,b,1 b,c,3 c,d,1 

i have not been able figure out yet. can think of using recursive query within sqldf. wondering if there more efficient way of doing this.

sorry first time posting on stackoverflow , not figure out how show dataset, hence pasting pictures. apologize inconvenience.

using dplyr:

library(dplyr) df <- cbind(dataset[1:nrow(dataset)-1,], dataset[2:nrow(dataset),]) names(df) <- c("timestamp1", "session1", "event1", "timestamp2", "session2", "event2")  > df %>% filter(session1==session2) %>% count(event1, event2)  source: local data frame [4 x 3] groups: event1    event1 event2 n 1           b 1 2      b      c 3 3      c      d 1 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -