[R] adding a column to a matrix

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Thu Apr 26 11:46:08 CEST 2007


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



More information about the R-help mailing list