[R] computing sum of indicator variables
Stefan Böhringer
commercial at s-boehringer.de
Mon Jul 26 10:45:52 CEST 2004
My problem is as follows:
i is a list of integers of variable length. Now I want to compute a new
vector/array that contains 1's at the positions indicated in i. For
example:
c(2, 4) -> c(0, 1, 0, 1)
Using something like
i = i - c(0, i[2:length(i) - 1]);
sapply(i, function(x) c(rep(0, x - 1), 1)));
faces me with the problem of concatenating the result, which I could
somehow not find a solution for.
Thank you very much in advance.
Stefan
More information about the R-help
mailing list