I'm trying to filter a dataframe based on a date range using sqldf, like the example code below. I have data like the example data below. The datedf dataframe that gets returned by sqldf has no records. There are records in the SHV dataframe in that date range, can anyone see what I'm doing wrong and let me know how to filter by date range in sqldf. Dates are always tricky in r for me.
Code:
datedf<-sqldf("select field1
,fieldDate
from SHV
where fieldDate between '2004-01-01' and '2005-01-01'
")
Data:
dput(SHV[1:50,c("field1","fieldDate")])
structure(list(field1 = c(1378L, 1653L, 1882L, 2400L,
2305L, 2051L, 2051L, 2051L, 1796L, 2054L, 2568L, 1290L, 1804L,
1804L, 3855L, 1297L, 2321L, 2321L, 2321L, 2071L, 2071L, 2074L,
2588L, 1567L, 1317L, 1317L, 808L, 808L, 1321L, 2350L, 1586L,
2613L, 1590L, 2614L, 2107L, 1340L, 1085L, 1085L, 2365L, 1344L,
1601L, 1858L, 1603L, 1603L, 1860L, 2376L, 1355L, 1867L, 2382L,
1872L), fieldDate = structure(c(12551, NA, NA, 14057, 15337,
12919, 13336, 10325, 14984, 15643, 12864, 11242, 10749, 11207,
10602, NA, 12646, 15649, NA, NA, NA, NA, NA, 17015, 13938, NA,
16693, NA, NA, 12634, 12614, 10689, 12755, 10844, 11375, 4899,
17298, 10905, 11450, NA, 10330, 15429, 12634, 10504, 12625, 11081,
10939, NA, 12934, 11176), class = "Date")), .Names = c("field1",
"fieldDate"), row.names = c(NA, 50L), class = "data.frame")