title: Using apply() in place of a for loop
body: <p>So I have this for loop:</p>
  
  <pre><code>set.seed(11)
  k=10000  # replicates
  n=100    # sample size of each replication
  t.mean = 0 # initialize vector of trimmed means 
  for(i in 1:k){
    dat=rnorm(n)
    t.mean[i]=mean(dat,trim=.05)
  }
  mean(t.mean)
  var(t.mean)
  </code></pre>
  
  <p>I am attempting to replace the code involved in the for loop with an apply() function instead</p>
  
  <p>I figured this would work</p>
  
  <pre><code>set.seed = 11
  k = 10000
  n = 100
  t.mean = 0
  dat  = rnorm(n)
  dat = as.data.frame(dat)
  t.mean =apply(dat,c(1,2), mean,trim=.05)
  mean(t.mean)
  var(t.mean)
  </code></pre>
  
  <p>however, I do not get the same values as before and they do not stay the same either like in the previous case where a for loop is used. What exactly am I doing wrong when I am using apply?</p>