# [R] adding a column to a matrix

Thu May 3 15:06:50 CEST 2007

```Hello,

Please, consider the functions "pmin" and "pmax".

Tuesday, May 1, 2007, 3:29:54 PM, you wrote:

rc> thanks for the previous advice it seems to have worked what about the following

rc> l have the following dataset and would like to calculate the actual survival time by
rc>  if censoring time > survival time then actual survival time
rc> =survival time else its= censoring time.
rc>        treatmentgrp strata  censoringTime    survivalTime     censoring   actualsurvivaltim
rc>     [1,]             1      1       1.012159           1137.80922                0
rc>   [2,]             2      2      32.971439           247.21786                 0
rc>   [3,]             2      1      85.758253           797.04949                 0
rc>   [4,]             1      1      16.999171            78.92309                  0

rc>  l used matrix to genarate the data
rc> Vladimir Eremeev <wl2776 at gmail.com> wrote:
rc> m<-cbind(m,0)
m[m[,3]>>m[,4],5]<-1
rc> colnames(m)[5]<-"censoring"

rc> raymond chiruka wrote:
>>
>> i would like to add a variable to an existing matrix by manipulating 2
>> previous variables eg for the data
>>   m
>>          treat strata      censti     survTime
>>     [1,]     1      2  284.684074  690.4961005
>>     [2,]     1      1  172.764515   32.3990335
>>     [3,]     1      1 2393.195400   24.6145279
>>     [4,]     2      1   30.364771    8.0272267
>>     [5,]     1      1  523.182282  554.7659501
>>
>>   l would want to add a new column censoring by comparing ( if censti >
>> survtime then censoring=1) how do l go about it
>>   thanks
>>
>>   the code l used to generate the data is
>>    n=100
>>   > m=matrix(nrow=n,ncol=4)
>>   > colnames(m)=c("treat",  "strata", "censti", "survTime")
>>   > for(i in 1:100)
>> m[i,]=c(sample(c(1,2),1,replace=TRUE),sample(c(1,2),1,replace=TRUE),rexp(1,.002),rexp(1,.005))
>>   > m
>>
>>   l know its ugly but it seems to work
>>   any suggestions l still new at this
>>   thanks

--
Best regards,