[R] preserving date formats in functions

jween jween at rockwoodclinic.com
Tue Jun 5 21:44:58 CEST 2012


Hi there!

I have two date columns in a dataframe I need to selectively collapse based
on missing values and which date comes first (imported from an text file).
This is what I did:

RHSSP$CT				<- as.POSIXct(RHSSP$CT, format='%m/%d/%y %H:%M')
RHSSP$MRI				<- as.POSIXct(RHSSP$MRI, format='%m/%d/%y %H:%M')
RHSSP$Scan				<-
ifelse(is.na(RHSSP$MRI),RHSSP$CT,ifelse(is.na(RHSSP$CT),RHSSP$MRI,ifelse(RHSSP$CT>RHSSP$MRI,RHSSP$MRI,RHSSP$CT)))

RHSSP$CT and RHSSP$MRI remain properly formatted (e.g.: "2011-06-21 22:31:00
PDT") BUT RHSSP$Scan does not (e.g.: 1294076700)

I can't figure out how to maintain the proper format during the replacement.
Looks like the replacement inherits the ifelse comparison format.

Any suggestions?

Many thanks

Jon

--
View this message in context: http://r.789695.n4.nabble.com/preserving-date-formats-in-functions-tp4632435.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list