[R] Comparing 2 dale columns
    Patrick Casimir 
    patrcasi at nova.edu
       
    Wed Aug 23 16:53:31 CEST 2017
    
    
  
Dear R fellows,
I created a new column Date_flag to compare the dates of COL1 and COL2 using the code
below. But it showed that 5/1/15 is greater than 6/1/2014 and 5/1/2015 greater than
7/1/2014 despite the year is greater. How do I fix that? I did try to format as %y/%m/%d
 but it does not fix that.
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
COL1       COL2
6/1/14     5/1/15
7/1/14     5/1/15
data$COL2<- as.Date(as.character(data$COL2, format="%y/%m/%d"))
data$COL1<- as.Date(as.character(data$COL1, format="%y/%m/%d"))
	[[alternative HTML version deleted]]
    
    
More information about the R-help
mailing list