[R] Break into Parts

2006-04-28 Thread 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]]

Re: [R] Break into Parts

2006-04-28 Thread Uwe Ligges
sumanta basak wrote: 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. x - 1:72 apply(matrix(x, ncol=12), 2, sd) Uwe Ligges Thanks, Sumanta.

Re: [R] Break into Parts

2006-04-28 Thread Gabor Grothendieck
Try this: tapply(x, cut(x, 12), sd) On 4/28/06, sumanta basak [EMAIL PROTECTED] wrote: 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.

Re: [R] Break into Parts

2006-04-28 Thread Liaw, Andy
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

Re: [R] Break into Parts

2006-04-28 Thread Gabor Grothendieck
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