[R] Break into Parts
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Apr 28 15:03:57 CEST 2006
Good point.
Following Andy's comment sd(matrix(sort(x), nc=12))
could also be used if you want them broken up
by 6 smallest, next 6 smallest, etc. although
there might be differences in the case of ties.
Using tapply here are a number of ways of breaking
it up (the first three give the same answer as
sd(matrix(x,nc=12))) while the others form the
groups in different ways:
tapply(x, gl(12, 6), sd)
tapply(x, rep(1:12, each = 6), sd)
tapply(sort(x), gl(12, 6), sd)
tapply(x, rep(1:12, 6), sd)
tapply(sort(x), rep(1:6, 12), sd)
tapply(sort(x), rep(1:6, each = 12), sd)
On 4/28/06, Liaw, Andy <andy_liaw at merck.com> wrote:
> You didn't say _how_ you want the vector to be broken up,
> so you get two different answers from Uwe and Gabor. Uwe's
> answer group every six elements into one group, in the order
> they appear in the vector (which, BTW, can be simplified to
> just sd(matrix(x, ncol=12)). Gabor's answer put the smallest
> six into one group, the next smallest six into the second
> group and so on. You'll have to decide which is the one
> you want.
>
> Andy
>
> From: sumanta basak
> >
> > Hi R-Experts,
> >
> > I have a vector of length 72. I want to break it into 12
> > parts and want to take standerd deviation of each group.
> > Please help me in this regard.
> >
> > Thanks,
> > Sumanta.
> >
> >
> > ---------------------------------
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list