0

I have a time-stamped dataset like the following

t = c("2006-01-02 09:09:38 UTC", "2006-01-04 08:45:34 UTC", "2006-01-10 12:55:41 UTC", 
      "2006-01-20 09:33:54 UTC", "2006-02-02 11:36:06 UTC", "2006-02-15 08:51:03 UTC", 
      "2007-06-07 16:26:56 UTC", "2008-04-01 13:20:20 UTC", "2008-04-03 10:53:50 UTC")

seller = c("A", "E", "B", "B", "C", "F", "A", "B", "E")
buyer = c("B", "F", "A", "C", "B", "G", "C", "A", "G")

data = cbind.data.frame(t, seller, buyer)

I would like to compute the time to transitive closure for all the possible two-paths. This is what I mean:

I have two two-paths, i.e.

A->B, B->C
E->F, F->G

and I want to compute the time to observe

A->C
E->G

The desired outputs should be:

# 1. List with all the two-paths structures that ultimately produce a transitive closure
out1 = list(o1 = data[c(1,4,7), ], o2 = data[c(2,6,9), ])

out1

$o1
                        t seller buyer
1 2006-01-02 09:09:38 UTC      A     B
4 2006-01-20 09:33:54 UTC      B     C
7 2007-06-07 16:26:56 UTC      A     C

$o2
                        t seller buyer
2 2006-01-04 08:45:34 UTC      E     F
6 2006-02-15 08:51:03 UTC      F     G
9 2008-04-03 10:53:50 UTC      E     G


# 2. Time to transitive closure
out2 = list(o1 = difftime(out1$o1[3,1], out1$o1[1,1]), o2 = difftime(out1$o2[3,1], out1$o2[1,1]))

out2

$o1
Time difference of 521.262 days

$o2
Time difference of 820.0474 days

Thanks for your help!

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
EffeBi
  • 41
  • 3
  • Is this question different from your previous question ? https://stackoverflow.com/questions/54126150/time-stamped-relational-dataset-compute-time-of-each-two-path-to-close – Ronak Shah Jan 14 '19 at 01:30
  • It is slightly well specified – EffeBi Jan 14 '19 at 10:05

0 Answers0