[R] creating random numbers
Petr Klasterecky
klaster at karlin.mff.cuni.cz
Wed Apr 25 16:48:38 CEST 2007
?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
More information about the R-help
mailing list