On Feb 21, 2010, at 2:19 PM, Newbie19_02 wrote:


Hi everyone,

I have another fairly simple question. I want to take the earliest of two
dates from these two date columns.  I've tried converting the dates to
numbers and just get a vector full of NA's. I've also tried using the chron function to compare the two and have been unsuccessful. I then tried to use:temp.2 <- as.POSIXct(strptime(temp, '%d/%m/%Y')) where temp is character vector of one of the date columns this did not work either. I'm not sure
what to do now.

date_1             date_2
2005-11-25       <NA>
2007-10-23       <NA>
<NA>               1999-12-13
2006-01-25       <NA>
2006-06-12       <NA>
2005-08-08       <NA>
2007-12-12       <NA>
2008-04-29       <NA>
2005-03-28       <NA>
2004-11-18 2000-11-02
2006-03-16       <NA>
2007-01-17       <NA>

We cannot tell from that output what data type you are working with. You may not be working with Dates at all. You also have not offered the code that is not working. If they are dates, then pmin should work well.

> pmin(as.Date("2004-11-18"), as.Date("2000-11-02"))
[1] "2000-11-02"

Next time use dput to allow unambiguous communication. (The fact that you are not using either dput or dump suggests you have not yet spent enough effort at reading the Posting Guide.)

--
David


Thanks for your help,
Natalie
--
View this message in context: 
http://n4.nabble.com/Comparing-two-date-columns-tp1563776p1563776.html
Sent from the R help mailing list archive at Nabble.com.

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

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

Reply via email to