-3

I am trying to write the R code for the expression given in the image for calculation purposes. I tried to use two loops and sapply function but I failed. Can anyone suggest a suitable code for the calculation of this expression?

enter image description here

I tried below lines given in the image.

R Code tried:

R Code tried

Sinval
  • 1,315
  • 1
  • 16
  • 25
Bilal Para
  • 65
  • 1
  • 8
  • You should show us what you tried – Rhesous Aug 13 '18 at 14:10
  • 2
    "I tried to use two loops and sapply function but i failed". Can you post that in your question and explain which part specifically and how it didn't work? – acylam Aug 13 '18 at 14:10
  • I have added the tried R code in the image. – Bilal Para Aug 13 '18 at 14:18
  • Welcome to SO! This community has a few rules [rules](https://stackoverflow.com/help/on-topic) and [norms](https://stackoverflow.com/help/how-to-ask), and following them will help you get a good answer to your question. – DanY Aug 13 '18 at 14:18
  • 3
    In addition, you might want to review [this page](https://stackoverflow.com/help/mcve) for how to provide an MCVE (a minimum, complete, and verifiable example). There's also [this page](https://stackoverflow.com/a/5963610/4573108) that offers guidance for R-specific MCVEs. Finally, it's best to avoid using images of code/data and [here's why](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557). – DanY Aug 13 '18 at 14:18

1 Answers1

1

Please see as below:

gamma <- 1.5
s <- 1
k <- 3
i <- s:k
j <- lapply(i, function(x) 0:x)

prod_i <- sapply(j, function(x) prod(k + gamma - x))
f <- sum(factorial(k) / factorial(k - i) * prod_i)
f
# [1] 637.875
Artem
  • 3,304
  • 3
  • 18
  • 41