[R] controling the size of vectors in a matrix

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Thu May 17 12:06:30 CEST 2007


1) Your colnames need 4 elements and not 3
2) Utilize the argument 'n' in your random number generators

Your codes could be simplified as:

  m <- cbind( treatmentgrp  = sample( 1:2, n, replace=T ),
              strata        = sample( 1:2, n, replace=T ),
              survivalTime  = rexp( n, rate=0.07 ),
              somethingElse = rexp( n, rate=0.02 ) )

Regards, Adai



raymond chiruka wrote:
> hie R users
>    
>   l have the following matrix
>       n=20
>       m<-matrix(nrow=n,ncol=4)
>       colnames(m)=c("treatmentgrp","strata","survivalTime")                  
>           for(i in 1:n) m[i,]<-c(sample(c(1,2),1,replace=TRUE),sample(c(1:2),1,replace=TRUE),rexp(1,0.07),rexp(1,0.02))                                                                  
>    
>       print(m)
>     1.l would like to control the size of the treatment variable eg treatment 1=size 5 treatment 2=size 15.
>   
>   2. l would also want to control the size of the strata ie in treatment 1 divide the strata in to 2 etc.
>   
>   3. For the survival time l would like to have treatment 1-strata 1  using a different rate  from treatment 2 -strata 2 etc to generate  the survival time.
>   
>   the program l used above does nt do this so if you can help
>   
>   thanks 
>   
>        
> ---------------------------------
> Building a website is a piece of cake. 
> 
> 	[[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.
> 
> 
>



More information about the R-help mailing list