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
---------------------------------
[[alternative HTML version deleted]]
just try:
cbind(m, m[, "censti"] > m[, "survtime"])
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "raymond chiruka" <rtchiruka at yahoo.com>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, April 26, 2007 11:31 AM
Subject: [R] adding a column to a matrix
>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
>
>
>
>
> ---------------------------------
>
>
> [[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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
m<-cbind(m,0) m[m[,3]>m[,4],5]<-1 colnames(m)[5]<-"censoring" 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 > >-- View this message in context: http://www.nabble.com/adding-a-column-to-a-matrix-tf3650601.html#a10197380 Sent from the R help mailing list archive at Nabble.com.
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> thanks in advance 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, Vladimir mailto:wl2776 at gmail.com --SevinMail--