Re: [R] Summation in R

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Fri 06 Oct 2006 - 11:09:22 GMT

I was off for few days and as nobody seems to answer I will try again.

It is probably not trivial with matrix (possibly with combination of outer and some subsequent selection) but if you can transfer it to data frame (or list) you could use mapply

tj <- 1:5
vj <- matrix(1:25, 5,5)
mapply("*", data.frame(vj), tj)

anyway it is always advisable to provide some example what you want to achieve. Usually when I try to elaborate an example I find the answer myself.

HTH
Petr

On 3 Oct 2006 at 11:50, Dina Said wrote:

Date sent:      	Tue, 03 Oct 2006 11:50:39 +0200
From:           	Dina Said <dinasaid@gmail.com>
To:             	r-help@stat.math.ethz.ch
Subject:        	Re: [R] Summation in R

>
> Thanks Pikal for your reply
> I want element wise summation. If t is a vector of 5, v is a matrix
> of 5*5 then I want the answer to be a matrix of 5*5 by
> multiplying each element in t (t_j) by each vector in v (v_j).
> Dina Petr Pikal wrote:
>
> Hi
>
> you shall probably to be more specific
>
> tj<-rnorm(5)
> vj<-matrix(25,5,5)
> sum(tj*vj)
> [1] 149.2977
>
> gives you an answer but maybe not the answer you want.
>
> HTH
> Petr
>
>
> On 3 Oct 2006 at 8:58, Dina Said wrote:
>
> Date sent: Tue, 03 Oct 2006 08:58:15 +0200
> From: Dina Said [1]<dinasaid@gmail.com>
> To: [2]r-help@stat.math.ethz.ch
> Subject: [R] Summation in R
>
>
>
> Hello!
>
> Maybe this is a trivial question as I'm still a new baby in R but I
> wish that u will help me.
>
> I want to calculate the following
>
> U= sum (t_j*v_j)
>
> where t_j is a vector
> and v_j is the matrix
>
> Thanks
> Dina
>
> ______________________________________________
> [3]R-help@stat.math.ethz.ch mailing list
> [4]https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> [5]http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.
>
>
> Petr Pikal
> [6]petr.pikal@precheza.cz
>
> References
>
> 1. mailto:dinasaid@gmail.com
> 2. mailto:r-help@stat.math.ethz.ch
> 3. mailto:R-help@stat.math.ethz.ch
> 4. https://stat.ethz.ch/mailman/listinfo/r-help
> 5. http://www.R-project.org/posting-guide.html
> 6. mailto:petr.pikal@precheza.cz
> ______________________________________________
> R-help@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 and provide commented,
> minimal, self-contained, reproducible code.

Petr Pikal
petr.pikal@precheza.cz



R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Fri Oct 06 21:14:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 06 Oct 2006 - 12:30:09 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.