[R] creating Surv object from character vector

Erik Iverson eiverson at NMDP.ORG
Tue Sep 29 21:35:05 CEST 2009


> 
> identical(srv, ???(srv.char)) to return TRUE, where ??? is some unknown
> function.  I don't think it exists, but maybe I'm wrong. I suppose it
> would be easy enough to roll my own...
> 

FYI, This works in my simple case for right-censored data... it takes as input a vector like c("1", "2+", "3+", "5") 

as.Surv <- function(x) {
  Surv(as.integer(sub("\\+", "", x)),
       as.integer(ifelse(regexpr("\\+", x) > -1, 0, 1)))
}

> identical(srv, as.Surv(srv.char))
[1] TRUE




More information about the R-help mailing list