title: trying to create a loop function to sum random variables in R
body: <p>Please see below my code for trying to run a loop of 10000 iterations, every time the code loops I want it to select a new value for my two random variables labelled: <code>premium_A_1</code> and <code>cost_of_claim</code>.</p>
  <pre><code>for (i in 1:10000){
  
    profit_A_scheme1 = c()
    premium_A_scheme1=sample(c(200,170,140), size = 1, replace = TRUE, prob = s.d_scheme1) 
    costclaim_A= runif(1, 0, 400)
    profit_A_scheme1[i] = premium_A_scheme1 - costclaim_A
    
  }
  </code></pre>
  <p>The code returns<code> profit_A_scheme_1 = (NA, NA, ..., x)</code> when I was hoping for <code>profit_A_scheme_1 = (x1, x2, ..., xn)</code>. Essentially only assigning a value to the final loop and <code>NA</code> for every loop previous. In case anyone tries to run this code the probabilities for the premium r.v. are <code>prob = (0.4510610, 0.3207926, 1 - 0.4510620 - 0.3207926)</code>.</p>
  <p>Thanks for any help you are able to offer as I've been stuck on this for a minute now.</p>