sample(1:2, 10, replace=TRUE)> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of raymond chiruka > Sent: Wednesday, April 25, 2007 9:45 AM > To: r-help at stat.math.ethz.ch > Subject: [R] creating random numbers > > l want to create a column of 1 and 2 randomly what > command should l use > eg > treatment strata > > 1 1 > 2 0 > 1 1 > 2 1 > 2 0 > 2 1 > 2 0 > 1 0 > these should be created randomly > > secondly if l have something like > for (i in 1:n ) df =c(1,rexp(1,.001),rexp(1,.002)) can l > add an if statement in side the c maybe to compare the 2 > exponential numbers to create another variable > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
l want to create a column of 1 and 2 randomly what command should l use eg treatment strata 1 1 2 0 1 1 2 1 2 0 2 1 2 0 1 0 these should be created randomly secondly if l have something like for (i in 1:n ) df =c(1,rexp(1,.001),rexp(1,.002)) can l add an if statement in side the c maybe to compare the 2 exponential numbers to create another variable --------------------------------- [[alternative HTML version deleted]]
?sample sample(c(1,2),10,replace=TRUE) P. raymond chiruka napsal(a):> l want to create a column of 1 and 2 randomly what command should l use > eg > treatment strata > > 1 1 > 2 0 > 1 1 > 2 1 > 2 0 > 2 1 > 2 0 > 1 0 > these should be created randomly > > secondly if l have something like > for (i in 1:n ) df =c(1,rexp(1,.001),rexp(1,.002)) can l add an if statement in side the c maybe to compare the 2 exponential numbers to create another variable > > > --------------------------------- > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic