Hi, I have dates in the following format: 4/8/2006 (MM/DD/YYYY). I need to have R compare date A to date B to figure out which one is more recent. Is there a way to do that? Simply using the '>' or '<' signs doesn't seem to work. I think in this case R treats '/' as a division sign and gives me erroneous results. Thanks a lot for your help. Irina ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. [[alternative HTML version deleted]]
Convert to Date and then compare;> x <- as.Date("4/8/2006", "%m/%d/%Y") > y <- as.Date("5/10/2007", "%m/%d/%Y") > x>y[1] FALSE>On Nov 28, 2007 2:44 PM, Irina Burmenko <iburmen at yahoo.com> wrote:> Hi, > > I have dates in the following format: 4/8/2006 (MM/DD/YYYY). I need to have R compare date A to date B to figure out which one is more recent. Is there a way to do that? Simply using the '>' or '<' signs doesn't seem to work. I think in this case R treats '/' as a division sign and gives me erroneous results. > > Thanks a lot for your help. > Irina > > > ____________________________________________________________________________________ > Never miss a thing. Make Yahoo your home page. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Irina, you must have them in character format. You need to convert to Date type. mydates = as.Date(mydates, "%m/%d/%Y") HTH. Horace -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Irina Burmenko Sent: Wednesday, November 28, 2007 11:44 AM To: Horace Tso; r-help at r-project.org Subject: [R] Dates in R Hi, I have dates in the following format: 4/8/2006 (MM/DD/YYYY). I need to have R compare date A to date B to figure out which one is more recent. Is there a way to do that? Simply using the '>' or '<' signs doesn't seem to work. I think in this case R treats '/' as a division sign and gives me erroneous results. Thanks a lot for your help. Irina ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. [[alternative HTML version deleted]] ______________________________________________ R-help at 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.