Hello,
   I have some trouble in terms of using integrate function in R.

f1 is a function of p and x where x is supposed to be a vector. (See the
code).
Then I want to write function f2 which is a function of the vector
 x after I integrate out p.
  Can some one give me some help? Many thanks!
                             Hannah

> f1 <- function (p,x)
+   {
+    y <- p*x+(1-p)*x^{2}
+       prod(y)
+   }
>
> f2 <- function(x)
+     {
+     integrate(f1, 0,1, x)
+      }
> f2(x=c(1,2))
Error in integrate(f1, 0, 1, x) :
  evaluation of function gave a result of wrong length
In addition: Warning messages:
1: In p * x :
  longer object length is not a multiple of shorter object length
2: In (1 - p) * x^{ :
  longer object length is not a multiple of shorter object length

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to