I have some longitudinal data which I want to convert to a directed edgelist and a nodelist. The edgelist has a weight column which shows the counts of let change from one day to the next. Here are the longitudinal data:
longdata <- data.frame( id = c(1L,1L,1L,1L,1L,2L,2L,2L,
2L,2L,3L,3L,3L,3L,3L),
day = c(1L,2L,3L,4L,5L,1L,2L,3L,
4L,5L,1L,2L,3L,4L,5L),
let = c("o","s","s","o","s","a",
"b","a","b","a","c","c","d","d","c"),
gender = c("F","F","F","F","F","M",
"M","M","M","M", "F","F","F","F","F"),
age = c(23L,23L,23L,23L,23L,31L,
31L,31L,31L,31L,28L,28L,28L,28L,28L)
)
Here is the edgelist I want to obtain:
from to weight
o o 0
o s 2
s o 1
s s 1
a a 0
a b 2
b a 2
b b 0
c c 1
c d 1
d c 1
d d 1
Here is the nodelist I want to obtain:
id gender age
1 F 23
2 M 31
3 F 28