r - Cannot filter on date field converted from numeric -
Using R, when I query a SQLite database, it returns a date field in duplicate form
When I change it to a date field, it looks okay, but I can not filter it. Here is a toy example
df < - data.frame (dbl = c (1408258800, 1409382000, 1324108800)) df $ dt & lt; - as.Date (df $ dbl / (60 * 60 * 24), original = '71 71-01-01') str (df) # 'data.frame': 3 obs 2 variables: # $ dbl: num 1.41e + 09 1.41e + 09 1.32e +09 # $ dt: Date, Format: "2014-08-17" "2014-08-30" "2011-12-17" Df [df $ dbl = 1408258800 ,] #dbl # 1 1408258800 2014-08-17 DF [DF $ DT == "2014-08-17", #] [1] DBL DT # & lt; 0 rows & gt; (Or 0-length line.Name) or df [df $ dt as of.Date ("2014-08-17"),] # [1] dbl dt # & lt; 0 rows & gt; (Or 0-length line.Name) I think there is some pretty basic unavailable as the date field or the subsequent processing to get the initial results
TIA
as.Date Although you expect a number, you pass this decimal number. As a result: as.numeric (df $ dt [1]) # [1] As of 16299.29. Numerical (as.Date ("2014-08-17")) # [1] 1629 9 And these are not identical I think that as.Date.numeric < / Code> Should handle it differently or give a warning, but it is not a bug altogether. Use integer partitions instead:
DF $ dt < - as.Date (df $ dbl% /% (60 * 60 * 24), original = '197-01-01') df [df $ dt == as.Date ("2014- 08-17") ,] #dbl DT # 1 1408258800 2014-08-17
Comments
Post a Comment