Warning message: In if (n <= 1) { : the condition has length > 1 and only the first element will be used

I have the function
We are told to do set.seed(100) and we know lambda=10

set.seed(100)
lambda<-10
F<-function(lambda,k) {
X<-NULL
X= exp(-lambda) * sum((lambda ^ seq(0 , k)) / factorial(seq(0 , k)))
return(X)

I then had to find F when k=3 so I did

F3<-F(10,3)
F3

I also tried

k<-3
lambda<-10
F3<-F(lambda,k)
F3
when I run either of those codes I get
Warning message:
In if (n <= 1) { :
the condition has length > 1 and only the first element will be used
can anyone help solve why this is happening??

Try this

set.seed(100)
f <- function(x, y) exp(-x) * sum((x^seq(0, y)) / factorial(seq(0, y)))
f(10,3)
#> [1] 0.01033605

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.