Consider
na=43; nb=5; x=1:na
ns=rep(na %/% nb, nb) + (1:nb = na %% nb)
split(x, rep(1:nb, ns))
Heikki Kaskelma
On Fri, 2 Feb 2007, jim holtman [EMAIL PROTECTED] wrote:
This might do what you want:
# test data
x - 1:43
nb - 5 # number of subsets
# create vector of lengths of subsets
ns -
is an exact multiple of
the number of groups).
-- TMK --
212-460-5430home
917-656-5351cell
From: Kaskelma, Heikki [EMAIL PROTECTED]
To: jim holtman [EMAIL PROTECTED],Talbot Katz [EMAIL PROTECTED]
CC: r-help@stat.math.ethz.ch
Subject: RE: [R] Can this loop be delooped?
Date: Fri, 2 Feb
Hi.
I have the following code in a loop. It splits a vector into subvectors of
equal size. But if the size of the original vector is not an exact multiple
of the desired subvector size, then the first few subvectors have one more
element than the last few. I know that the cut function could
This might do what you want:
# test data
x - 1:43
nb - 5 # number of subsets
# create vector of lengths of subsets
ns - rep(length(x) %/% nb, nb)
# see if we have to adjust counts of initial subsets
if ((.offset - length(x) %% nb) != 0) ns[1:.offset] = ns[1:.offset] + 1
# create the