[R] creating Surv object from character vector

Erik Iverson eiverson at NMDP.ORG
Tue Sep 29 23:03:04 CEST 2009


> 
> 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
> 

But Do NOT use "as.integer" with real data, which may contain fractions of course.  I was too eager to get identical to return TRUE because I had only used integers in my sample dataset! Oops. 




More information about the R-help mailing list