'apply Integrate function to a vector

I'm a newbie to R programming and I have an assignment to submit so my prob is the following: I wrote the following function :

  



and I should be using integrate () function to calculate phi(x) for all x of the vector quantiles and store them in a vector named probs.

I started the following and I got blocked

Rep <- function (x) {

vector <-integrate (phi, lower = Inf , upper = x)$Value } 

Not sure if this is the right way to apply the function integrate() to a vector. Your help is much appreciated



Solution 1:[1]

You could do the following:

phi <- function(x)exp(-x^2/2)/sqrt(2 * pi)
quantiles <- seq(from = 0, to = 5.5, by = 0.01) 


fun<-Vectorize(function(x)integrate(phi,-Inf, x)[[1]])

fun(quantiles)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 onyambu