title: Conditional probability experiment in R
body: <p>Here is my code</p>
  
  <pre><code>library(dplyr)
  
  rain_vector &lt;- sample(c(0,1), 1000000, replace = T, prob= c(0.2,0.8))
  
  for(el in 1:10){
  
  df &lt;- data.frame(rain = rain_vector )
  df &lt;- df %&gt;% mutate(A= if_else(rain == 1, sample(c(0,1), 1, replace = T, prob= c(1/3,2/3)),
                            sample(c(0,1), 1, replace = T, prob= c(2/3,1/3))))
  
  print(NROW(df[df$A==1,]))
  print(NROW(df[df$A == 1 &amp; df$rain == 1, ]))
  print(NROW(df[df$rain == 1,]))
  print("______________")
  
  }
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>[1] 0
  [1] 0
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 800325
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 1000000
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 1000000
  [1] 800325
  [1] 800325
  [1] "______________"
  [1] 1000000
  [1] 800325
  [1] 800325
  [1] "______________"
  </code></pre>
  
  <p>None of the results makes sense to me. Let us look at the last one. Case <code>A = 1</code> is happening always, while it is supposed to happen with probability 1/3 and 2/3 depending on rain. Is there something about <code>dplyr</code> package. Any suggestions?</p>