Re: [R] controling the size of vectors in a matrix

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Thu, 17 May 2007 11:06:30 +0100

  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.
>
>
>



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. Received on Thu 17 May 2007 - 10:22:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 May 2007 - 10:31:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.