Skip to content
Prev 309218 / 398506 Next

summation sign

Hi Sara,

Not very clear either.

You mentioned you want to repeat the sum 5 times.? Is it on the same x variable or different x variables?
If you want to repeat the sum 5 times on the same x variable,

x1<-c(.3,.2,.1)
?fun1<-function(x,i){
?res<-lapply(1:i,function(y) -sum(log(1-x^2)))
?res1<-unlist(res)
?res1}
?fun1(x1,5)
#[1] 0.145183 0.145183 0.145183 0.145183 0.145183

But, if you want? to do the sum on different vector of same or different length

x1<-c(.3,.2,.1)
?x2<-c(.5,.6,.1)
?x3<-c(.1,.6,.4)
?x4<-c(.2,.7.,.3)


fun1<-function(x1,...){
?res1<-lapply(list(x1,...),function(x) -sum(log(1-x^2)))
?res2<-unlist(res1)
?res2}
?fun1(x1,x2,x3,x4)
#[1] 0.1451830 0.7440195 0.6306908 0.8084772

#or
fun2<-function(x1,x2,x3,x4){
?res1<-lapply(list(x1,x2,x3,x4),function(x) -sum(log(1-x^2)))
?res2<-unlist(res1)
?res2}
?fun2(x1,x2,x3,x4)
#[1] 0.1451830 0.7440195 0.6306908 0.8084772
A.K.








----- Original Message -----
From: Sara Farooqi <sffarooqi at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Sunday, October 28, 2012 2:39 AM
Subject: Re: [R] summation sign

hi Arun,
thank you for? email. No I want to repeat the sum 5 times. So i is 5
and hence there are 5 x-variables. Each of these x variables is a 3x1
vector for example.
So my question is how do I get R to repeat the sum 5 times and
recognize that each x is a 3x1 vector.
thank you!
On Sat, Oct 27, 2012 at 11:30 PM, arun <smartpink111 at yahoo.com> wrote:
Message-ID: <1351440172.20335.YahooMailNeo@web142605.mail.bf1.yahoo.com>
In-Reply-To: <CAG68dva4MLdM+sxcirK64gojnybNbTiBsNMbLpCDXA=r9+t+Fg@mail.gmail.com>