Dear all, As a novice user of R I ran into a problem that's quite hard for me to resolve. I have a database containing data of a clinical trial in which patients are included that survived or died:
x <- matrix(data=c(1:5,0, "1/1/2012 00:00:00",0,0,"1/7/2012 00:00:00"), nrow=5, ncol=2, dimnames= list(NULL,c("ID", "dateofdeath"))) My file is a .csv so I don't have a problem with the brackets, don't know how to show you the idea without the brackets... I want to be able to do calculations with the values in the column x$dateofdeath so use the chron-package for this: library(chron) x$dateofdeath<- as.character(x$dateofdeath) dateofdeath1 <- t(as.data.frame(strsplit(x$dateofdeath,' '))) row.names(dateofdeath1) <- NULL x$dateofdeath<- chron(dates=dateofdeath1[,1],times=dateofdeath1[,2],format=c('d-m-y','h:m:s')) When I run this script the database looks like this: > x ID dateofdeath 1 1 (NA NA) 2 2 (01-01-12 00:00:00) 3 3 (NA NA) 4 4 (NA NA) 5 5 (01-07-12 00:00:00) The times are how I want them to be, the zero's on the other hand should stay that way. In other words: how can I make the database look like this: > x ID dateofdeath 1 1 0 2 2 (01-01-12 00:00:00) 3 3 0 4 4 0 5 5 (01-07-12 00:00:00) I already tried replacing the NA's with 0 which gives me 1-1-1970 (the default date by chron) and making a subset and only replacing values that are not equal to zero doesn't work either: d <- x ## above coding for chron with x replaced with d ## mat <- match(x$ID, d$ID) x$dateofdeath <- d$dateofdeath[mat] Does anybody know how to resolve this issue? Thanks in advance! Cheers, Rick Admiraal [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org 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.