Re: [R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Kevin > E. Thorpe > Sent: Tuesday, March 31, 2015 10:53 AM > To: Duncan Murdoch > Cc: R Help Mailing List > Subject: Re: [R] Randomly interleaving data frames while preserving >

Re: [R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Tom Wright
samples<-sample(c(rep(1,10),rep(2,10),rep(3,10)),30) samples[samples==1]<-1001:1010 samples[samples==2]<-2001:2010 samples[samples==3]<-3001:3010 fullDf<-rbind(df1,df2,df3) fullDf[sort(order(samples),index.return=TRUE)$ix,] On Tue, 2015-03-31 at 13:05 -0400, Kevin E. Thorpe wrote: > Hello. > >

Re: [R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Kevin E. Thorpe
On 03/31/2015 01:44 PM, Duncan Murdoch wrote: On 31/03/2015 1:05 PM, Kevin E. Thorpe wrote: Hello. I am trying to simulate recruitment in a randomized trial. Suppose I have three streams (strata) of patients represented by these data frames. df1 <- data.frame(strat=rep(1,10),id=1:10,pid=1001:1

Re: [R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Duncan Murdoch
On 31/03/2015 1:05 PM, Kevin E. Thorpe wrote: > Hello. > > I am trying to simulate recruitment in a randomized trial. Suppose I > have three streams (strata) of patients represented by these data frames. > > df1 <- data.frame(strat=rep(1,10),id=1:10,pid=1001:1010) > df2 <- data.frame(strat=rep(2

Re: [R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Sarah Goslee
That's a fun one. Here's one possible approach. (Note that it can be done without using a loop, but I find that a loop here increases readability.) I wrote it to work on a list of data frames. If the selection is random, I'd set it up so that size is passed to the function, but selection is genera

[R] Randomly interleaving data frames while preserving order

2015-03-31 Thread Kevin E. Thorpe
Hello. I am trying to simulate recruitment in a randomized trial. Suppose I have three streams (strata) of patients represented by these data frames. df1 <- data.frame(strat=rep(1,10),id=1:10,pid=1001:1010) df2 <- data.frame(strat=rep(2,10),id=1:10,pid=2001:2010) df3 <- data.frame(strat=rep(3,