Suppose I have the current membership status of a group, i.e. names of members. Additionally, I have data on times when some new member may have been added to the group and / or an old member may have been removed from the group.
The task at hand is to recreate the membership of the group at all these points in time. I've looked around but did not find a ready solution for this problem. Does anybody know an elegant method of doing this?
Reproducible example:
Input:
periods <- 5
indx <- paste0("t-", seq_len(periods))
[1] "t-1" "t-2" "t-3" "t-4" "t-5"
current <- letters[seq_len(10)]
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
incoming <- setNames(letters[seq_len(periods) + 5], indx)
incoming[2] <- NA
t-1 t-2 t-3 t-4 t-5
"f" NA "h" "i" "j"
outgoing <- setNames(letters[seq_len(periods) + 10], indx)
outgoing[4] <- NA
t-1 t-2 t-3 t-4 t-5
"k" "l" "m" NA "o"
Output:
$current
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
$`t-1`
[1] "a" "b" "c" "d" "e" "g" "h" "i" "j" "k"
$`t-2`
[1] "a" "b" "c" "d" "e" "g" "h" "i" "j" "k" "l"
$`t-3`
[1] "a" "b" "c" "d" "e" "g" "i" "j" "k" "l" "m"
$`t-4`
[1] "a" "b" "c" "d" "e" "g" "j" "k" "l" "m"
$`t-5`
[1] "a" "b" "c" "d" "e" "g" "k" "l" "m" "o"
Disclaimer: I've written a solution for this which I will be posting as my answer to the question. The intent is to document this problem and a possible solution and to elicit other ingenious and / or existing solutions or improvements.
The function
create_mem_ts
(membership timeseries) will generate the desired output as posted in the question.Moreover, if
ctime
is a valid time-series class in the function above, the output from that can be used to generate membership on any time-stamp using the function (within the range in ctime) using this functionmemship_at
.