[R] select integer intervals from a integer space

Mao Jianfeng jianfeng.mao at gmail.com
Wed Dec 7 21:15:57 CET 2011


Dear Gene,

Thanks a lot for your kindness.

> isp <- data.frame(begin=c(1,5,6,15,31,51,102), end=c(7,9,13,21,49,52,109))
> isp
> ints = apply(isp, 1, function(x)seq(x[1],x[2]))
> ints
> ints = do.call(c, ints)
> ints
> ## option to fix if the regions are overlapping
> ## and you don't want overlapping regions resampled
> ints = unique(ints)
> ## sample from ints
> sample(ints, 5)
> sample(ints, 5, replace=TRUE)

I learned much from your code, such as the function do.call(). Could
you please give me more helps on finding ways to sample consecutive
integer interval?

And you may reply me through here
(http://stackoverflow.com/questions/8413990/selecting-integer-intervals-with-specific-intra-inter-length-from-random-integer/8421698#8421698).
This question have attracted several responses, but still now no
answer came out.

I am still struggling with it.

Best wishes,
Jian-Feng,



More information about the R-help mailing list