Re: [R] creating a new column

From: Schmitt, Corinna <Corinna.Schmitt_at_igb.fraunhofer.de>
Date: Tue, 08 May 2007 12:02:35 +0200

Hallo,

if you work with matrix you can use cbind to add columns.

Corinna   

-----Ursprüngliche Nachricht-----
Von: r-help-bounces_at_stat.math.ethz.ch [mailto:r-help-bounces_at_stat.math.ethz.ch] Im Auftrag von raymond chiruka Gesendet: Montag, 7. Mai 2007 16:28
An: r
Betreff: [R] creating a new column

hie l would like to create a 6th column "actual surv time" from the following data   

  the condition being
  if censoringTime>survivaltime then actual survtime =survival time   else actual survtime =censoring time   

  the code l used to create the data is   

       s=2
       while(s!=0){ n=20
         m<-matrix(nrow=n,ncol=4)
         colnames(m)=c("treatmentgrp","strata","censoringTime","survivalTime")
        for(i in 1:20)  m[i,]<-c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.007),rexp(1,.002))
        m<-cbind(m,0)
         m[m[,3]>m[,4],5]<-1
         colnames(m)[5]<-"censoring"
      print(m)
       s=s-1
          treatmentgrp strata censoringTime survivalTime censoring

[1,] 1 1 1.012159 1137.80922 0
[2,] 2 2 32.971439 247.21786 0
[3,] 2 1 85.758253 797.04949 0
[4,] 1 1 16.999171 78.92309 0
[5,] 2 1 272.909896 298.21483 0
[6,] 1 2 138.230629 935.96765 0
[7,] 2 2 91.529859 141.08405 0

  l keep getting an error message when i try to create the 6th column                            


        [[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 Tue 08 May 2007 - 10:35:24 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 Tue 08 May 2007 - 11:32:07 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.