title: Compare two dates in R
body: <p>I have a tab-separated text file that I imported to R. I used the following command for the import: </p>
  
  <pre><code>data = read.table(soubor, header = TRUE, sep = "\t", dec = ".", colClasses =c("numeric","numeric","character","Date","numeric","numeric"))
  </code></pre>
  
  <p>When I run <code>str(data)</code> to check the data-types of my columns I get:</p>
  
  <pre><code>'data.frame':   211931 obs. of  6 variables:
  $ DataValue   : num  0 0 0 0 0 0 0 0 0 NA ...
  $ SiteID      : num  1 1 1 1 1 1 1 1 1 1 ...
  $ VariableCode: chr  "Sucho" "Sucho" "Sucho" "Sucho" ...
  $ DateTimeUTC : Date, format: "2012-07-01" "2012-07-02" "2012-07-03" "2012-07-04" ...
  $ Latitude    : num  50.8 50.8 50.8 50.8 50.8 ...
  $ Longitude   : num  15.6 15.6 15.6 15.6 15.6 ...
  </code></pre>
  
  <p>A reproducible sample of the first 20 rows of my data is here:</p>
  
  <blockquote>
    <p>my_sample = dput(data[1:20,])</p>
  </blockquote>
  
  <pre><code>structure(list(DataValue = c(0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, 
  NA, NA, NA, NA, NA, NA, 0, 0, 0), SiteID = c(1, 1, 1, 1, 1, 1, 
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), VariableCode = c("Sucho", 
  "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", 
  "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", "Sucho", 
  "Sucho", "Sucho", "Sucho", "Sucho", "Sucho"), DateTimeUTC = structure(c(15522, 
  15523, 15524, 15525, 15526, 15527, 15528, 15529, 15530, 15531, 
  15532, 15533, 15534, 15535, 15536, 15537, 15538, 15539, 15540, 
  15541), class = "Date"), Latitude = c(50.77, 50.77, 50.77, 50.77, 
  50.77, 50.77, 50.77, 50.77, 50.77, 50.77, 50.77, 50.77, 50.77, 
  50.77, 50.77, 50.77, 50.77, 50.77, 50.77, 50.77), Longitude = c(15.55, 
  15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 
  15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 15.55, 
  15.55)), .Names = c("DataValue", "SiteID", "VariableCode", "DateTimeUTC", 
  "Latitude", "Longitude"), row.names = c(NA, 20L), class = "data.frame")
  </code></pre>
  
  <p>Now I want to filter my table by the date. Note that I'm running my code inside a <code>for</code> loop. First, I subset my data by 1st July 2012 and do some processing. Then, I subset my data by 2nd July and do some processing, and so on.. For example, I want to get all rows with date equal to 6th July 2012. I tried the code:</p>
  
  <pre><code>startDate = as.Date("2012-07-01");
  endDate = as.Date("2012-07-20");
  all_dates = seq(startDate, endDate, 1);
  
  #the following code I'm trying to run inside a loop...
  for (j in 1:length(all_dates)) {
      filterdate = all_dates[j];
      my_subset = my_sample[my_sample$DateTimeUTC == filterdate,]
      #now I want do do some processing on my_subset...
  }
  </code></pre>
  
  <p>But the above code returns an empty dataset starting from step 7 of the loop.</p>
  
  <p>So, for example:</p>
  
  <pre><code>subset_one = my_sample[my_sample$DateTimeUTC == all_dates[6],]
  </code></pre>
  
  <p>returns: <code>3 obs of 6 variables</code>.</p>
  
  <p>But, for some unknown reason, the example:</p>
  
  <pre><code>subset_two = my_sample[my_sample$DateTimeUTC == all_dates[7],]
  </code></pre>
  
  <p>returns: <code>0 obs of 6 variables</code>.</p>
  
  <p>(note: I edited the above code to make my problem 100% reproducible)</p>
  
  <p>Any ideas what I'm doing wrong?</p>