Carol.Kar
Carol.Kar

Reputation: 5355

Sum up with R base

Sorry, that I didn't wrote the sum function in latex. I tried $$ but that didn't work...

I am a beginner in R and I want to sum up:

Sum from i=0 to n by 1.054^i

I reserached the sum() function in R. However, it seems to me that is only can just add elements and not include an index or something.

So my question is: Can I solve that with a simple sum function or do I have to use a for loop for example?

I really appreciate your answer!

UPDATE

Here is a link to my sum(sorry that I cannot post it, but I need more reputation :(link )

Upvotes: 2

Views: 94

Answers (1)

eddi
eddi

Reputation: 49448

In R most operations are vectorized, it requires changing the mindset a bit from other languages and for this question the answer is rather than looping, you simply do the entire operation on your sequence of numbers "at once":

sum(1.054^(0:n))

Upvotes: 4

Related Questions