Re: [R] Trying to speed up an if/else statement in simulations

2012-06-19 Thread nqf
Perfect, I now have a choice of workable solutions. Thanks a lot for your help, much appreciated. Natalie -- View this message in context: http://r.789695.n4.nabble.com/Trying-to-speed-up-an-if-else-statement-in-simulations-tp4633725p4633862.html Sent from the R help mailing list archive at Nabb

Re: [R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread Rui Barradas
Hello, Try creating an index vector. In this case, I've called it 'one'. Then, 'n.one' is the number of ones in flag1. (Since data is an R function, I've renamed your example dat). n <- 10 # number of observations # First make up some data set.seed(123) dat <- data.frame(flag1=rbinom(n, 1,

Re: [R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread David Winsemius
On Jun 18, 2012, at 1:29 PM, nqf wrote: Dear R-help, I am trying to write a function to simulate datasets of size n which contain two time-to-event outcome variables with associated 'Event'/'Censored' indicator variables (flag1 and flag2 respectively). One of these indicator variables nee

Re: [R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread R. Michael Weylandt
I might try something like: data[data$flag1 == 1, "flag2"] <- runif(sum(data$flag1 == 1)) < 0.95 and similarly for the other case. Hope this helps, Michael On Mon, Jun 18, 2012 at 12:29 PM, nqf wrote: > Dear R-help, > > I am trying to write a function to simulate datasets of size n which conta

Re: [R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread Peter Alspach
r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of nqf Sent: Tuesday, 19 June 2012 5:30 a.m. To: r-help@r-project.org Subject: [R] Trying to speed up an if/else statement in simulations Dear R-help, I am trying to write a function to simulate datasets of size n whi

Re: [R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread William Dunlap
R] Trying to speed up an if/else statement in simulations > > Dear R-help, > > I am trying to write a function to simulate datasets of size n which contain > two time-to-event outcome variables with associated 'Event'/'Censored' > indicator variables (flag1

[R] Trying to speed up an if/else statement in simulations

2012-06-18 Thread nqf
Dear R-help, I am trying to write a function to simulate datasets of size n which contain two time-to-event outcome variables with associated 'Event'/'Censored' indicator variables (flag1 and flag2 respectively). One of these indicator variables needs to be dependent on the other, so I am creating