Re: [R] blockwise sums

2004-09-01 Thread Vicente Canto Casasola
Hi, all!! From the help page for 'aggregate': Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form. So here's the solution I found to this problem: blocksums - function(x,n) { temp - 1:length(x)-1 temp - list((temp%/%n)+1)

[R] blockwise sums

2004-08-31 Thread Lutz Prechelt
I am looking for a function like my.blockwisesum(vector, n) that computes sums of disjoint subsequences of length n from vector and can work with vector lengths that are not a multiple of n. It should give me for instance my.blockwisesum(1:10, 3) == c(6, 15, 24, 10) Is there a builtin

RE: [R] blockwise sums

2004-08-31 Thread Liaw, Andy
If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Andy From: Lutz Prechelt I am looking for a function like my.blockwisesum(vector, n) that computes sums of disjoint subsequences of length n from vector and can

Re: [R] blockwise sums

2004-08-31 Thread Barry Rowlingson
Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Did you test that? I get: my.blockwisesum(1:10, 3) Error in tapply(x, seq(1, length(x), by = n), sum, ...) : arguments must have same length Here's

Re: [R] blockwise sums

2004-08-31 Thread Wolski
Hi! ind-c(sort(rep(1:floor(length(x)/ 3 ) , 3 )) , floor(length(x)/ 3 )+1) by(x,ind,sum) my.blockwisesum-function(x,n,...) { ind-c(sort(rep(1:floor(length(x)/ n ) , n )) , floor(length(x)/ n )+1) return(tapply(x,ind,sum)) } /Eryk *** REPLY SEPARATOR ***

RE: [R] blockwise sums

2004-08-31 Thread Liaw, Andy
From: Barry Rowlingson Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Did you test that? I get: Of course not (slap on wrist)!! My apologies... Andy my.blockwisesum(1:10, 3)

Re: [R] blockwise sums

2004-08-31 Thread Dimitris Rizopoulos
- From: Lutz Prechelt [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, August 31, 2004 2:19 PM Subject: [R] blockwise sums I am looking for a function like my.blockwisesum(vector, n) that computes sums of disjoint subsequences of length n from vector and can work with vector

RE: [R] blockwise sums

2004-08-31 Thread Pfaff, Bernhard
Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Did you test that? I get: my.blockwisesum(1:10, 3) Error in tapply(x, seq(1, length(x), by = n), sum, ...) : arguments

Re: [R] blockwise sums

2004-08-31 Thread Peter Dalgaard
Barry Rowlingson [EMAIL PROTECTED] writes: Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Did you test that? I get: my.blockwisesum(1:10, 3) Error in tapply(x, seq(1, length(x), by =

Re: [R] blockwise sums

2004-08-31 Thread Gabor Grothendieck
Lutz Prechelt prechelt at pcpool.mi.fu-berlin.de writes: : : I am looking for a function like : my.blockwisesum(vector, n) : that computes sums of disjoint subsequences of length n from vector : and can work with vector lengths that are not a multiple of n. : : It should give me for instance

RE: [R] blockwise sums

2004-08-31 Thread Thomas Lumley
On Tue, 31 Aug 2004, Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } If x is large, rowsum() should be faster than tapply(). -thomas Andy From: Lutz Prechelt I am looking for a

RE: [R] blockwise sums

2004-08-31 Thread Berton Gunter
: [R] blockwise sums From: Barry Rowlingson Liaw, Andy wrote: If you insist, here's one way: my.blockwisesum - function(x, n, ...) { tapply(x, seq(1, length(x), by=n), sum, ...) } Did you test that? I get: Of course not (slap on wrist)!! My apologies