Estimating Normal Distribution Probability Using Simulation in R Question: Use simulations in R to numerically estimate $P(X<Y)$ for $X \sim N(0,1)$, $Y \sim N(1,5)$ with X and Y independent.
My Solution:
simfunc <-function(sims,n){
  res <- rep(0, sims)
  for(i in 1:sims){
    X <- rnorm(n, 0, 1)
    Y <- rnorm(n, 1, 5)
    count <-0
    for (j in 1:n){
      if(X[j] < Y[j])
        count=count+1
    }
    res[i] <-count/n
  }
  finalres <- mean(res)
  return(finalres)
}

So basically sims is the number of simulations we are running while n is the number of independent normal values we are generating. If X < Y, then count is incremented. Count/n gives the probability of X < Y for that simulation, and is stored in a result vector. Finally result vector mean is calculated.
Is my solution formulated correctly?
 A: Your code will run and give a correct answer, but it is written in Fortran-like style.
As R code, it is spectacularly inefficient because you're not making use of R's vectorizations.
Your code is also overly long and convoluted for the stated aim.
If indeed you simply want to  estimate the probability by simulation, as your question states, then much simpler and faster code would be:
> n <- 1e6
> X <- rnorm(n, 0, 1)
> Y <- rnorm(n, 1, 5)
> mean(X<Y)
[1] 0.578

Did you perhaps have some extra aims that you have failed to state? Was there some reason why you conducted multiple simulations and then combined them instead of generating all the random deviates at once?
Were you perhaps trying to estimate variability between simulation runs? Your code does not do that at present -- as your code stands, the multiple simulations (1:nsims) have no purpose but simply add to complexity.
Of course, you could compute the desired probability to full machine accuracy in R without using simulations by:
pnorm(1, sd=sqrt(26), lower.tail=FALSE). 

I assume there is some pedagogic reason why you want to use a simulation.
PS. As it stands, your question is likely to get closed because it is a pure code question and therefore out of scope for CV.
