tags:

views:

75

answers:

2

I have a simple R beginner's question:

How do I express the sum below most concisely in R?

sum_{i=1}^n a / (a+i)

I tried the following, but there must be a better way, without actually calling for:

r<-0
for(i in 1:n){ r <- r + (a / (a+i)) }

Thanks!

+3  A: 

I believe it's as simple as:

sum(a/(a+1:n))
Joshua Ulrich
+3  A: 

You just do:

r <- sum(a/(a+1:n))
nico