Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread PIKAL Petr
Hi one option is use embed fff<-function(vec, n=3) apply(embed(vec,n),1,prod) apply(A,2, fff) Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Edouard Hardy > Sent: Tuesday, September 03, 2013 9:34 AM > To: R

Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Gerrit Eichner
Ok, here is a bandmatrix solution "by hand": leftmatrix <- matrix( c( rep( 1, k), rep( 0, nrow(A) - k + 1)), byrow = TRUE, ncol = nrow(A), nrow = nrow(A) - k + 1) Gerrit Thank you very much for your answer. Unfortunately, I cannot use any package... Er, ... this is qui

Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Gerrit Eichner
Thank you very much for your answer. Unfortunately, I cannot use any package... Er, ... this is quite unusual! (Is this is homework?) Do you have a solution ? Well, take a look at the resulting bandmatrix leftmatrix. Yould can certainly build it yourself "by hand" somehow. I used the Matrix pa

Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Edouard Hardy
Thank you very much for your answer. Unfortunately, I cannot use any package... Do you have a solution ? Thank you in advance Edouard Hardy On Tue, Sep 3, 2013 at 11:49 AM, Gerrit Eichner < gerrit.eich...@math.uni-giessen.de> wrote: > Hello, Edouard, > > taking logs of A's elements (so that *

Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Gerrit Eichner
Hello, Edouard, taking logs of A's elements (so that * turns into +, so to say), using a left-multiplication with a certain band matrix of the package Matrix, and exponentiating the result again could provide a solution (see below). I know have the following problem: I have a matrix : A = 1