## Specify interventions using a matrix
p <- 5
n <- 10
A <- matrix(FALSE, nrow = n, ncol = p)
for (i in 1:n) A[i, (i-1) %% p + 1] <- TRUE
## Generate list of intervention targets and corresponding indices
target.list <- mat2targets(A)
for (i in 1:length(target.list$target.index))
sprintf("Intervention target of %d-th data point: %d",
i, target.list$targets[[target.list$target.index[i]]])
## Convert back to matrix representation
all(A == targets2mat(p, target.list$targets, target.list$target.index))
Run the code above in your browser using DataLab