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
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,
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
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
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
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
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
7 matches
Mail list logo