Search code examples
rr-mosaic

Return a data frame using replicate command


The "do" command from the mosaic package nicely returns a data frame by default.

require(mosaic)
require(Sleuth3)


nulldist1 <- do(10)*t.test(Incidents~shuffle(Launch),
                           data=case0401,var.equal=TRUE)$statistic
class(nulldist1)

Now, I'd like to use the replicate command to do the same thing. Is there an argument that one can set in the replicate command that will force it to return a data frame? I tried simplify="data.frame" but that didn't work.

nulldist2 <- replicate(10,{
  t.test(Incidents~shuffle(Launch),
         data=case0401,var.equal=TRUE)$statistic
})
class(nulldist2)

Any thoughts?


Solution

  • data.frame(result = replicate(10,t.test(rnorm(100),rnorm(100))$statistic))