Re: [R] product of successive rows

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Tue, 29 Jul 2008 07:13:47 -0400

Hi rcoder,

Assuming that the number of rows of your matrix x is even, try also:

x <- matrix(1:72,12)
apply(x,2, tapply, rep(1:(nrow(x)/2),each=2),prod)

# or using a function which argument "x" is your matrix

prod.mat=function(x) {
k=nrow(x)
g=rep(1:(k/2),each=2)
apply(x,2, tapply, g,prod)
}

prod.mat(x)

HTH, Jorge

On Sun, Jul 27, 2008 at 6:20 PM, rcoder <mpdotbook_at_gmail.com> wrote:

>
> Hi everyone,
>
> I want to perform an operation on a matrx that outputs the product of
> successive pairs of rows. For example: calculating the product between rows
> 1 & 2; 3 & 4; 5 & 6...etc.
>
> Does anyone know of any readily available functions that can do this?
>
> Thanks,
>
> rcoder
>
>
> --
> View this message in context:
> http://www.nabble.com/product-of-successive-rows-tp18681259p18681259.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 29 Jul 2008 - 11:20:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jul 2008 - 11:32:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive