What are the better options to convert a non-decreasing seq of occurrence times to a 0-1 seq? Thanks.
d<-c(3,5,9,12,15);
c(rep(0,d[1]-1),1,unlist(rbind(mapply(rep,0,diff(d)-1),1)))
What are the better options to convert a non-decreasing seq of occurrence times to a 0-1 seq? Thanks.
d<-c(3,5,9,12,15);
c(rep(0,d[1]-1),1,unlist(rbind(mapply(rep,0,diff(d)-1),1)))
I think this should do the same
d <- c(3,5,9,12,15);
x <- integer(max(d)) # initialize integer vector where all entries are zero;
# length(x) = max(d) (or last element of d)
x[d] <- 1L # set x to 1 at the position of each occurence