Home > Back-end >  Count how often two factors have the same output value
Count how often two factors have the same output value

Time:06-15

I want to calculate the number of times two individuals share the same group number. I'm working with quite a large dataset (169 individuals and over a 1000 observations (rows) of them) and I'm looking for an efficient way to count the occurrence of them being in the same group. My (simplified) data looks like this:

ID Group number Date Time
Aa 1 15-06-22 15:05:22
Bd 1 15-06-22 15:05:27
Cr 2 15-06-22 15:07:12
Bd 1 15-06-22 17:33:15
Aa 2 15-06-22 17:36:54
Cr 2 15-06-22 17:37:01
...

I would like my output data to look like this:

Aa-Bd Aa-Cr Bd-Cr ...
1 1 0

Or:

Occurrence Dyad
1 Aa-Bd; Aa-Cr
0 Bd-Cr

Or even a matrix might work. I've been trying to replicate the solution posed for this problem: enter image description here

Hope this helps!

  • Related