I'm getting some odd coefficients when I apply lm to dates that have been processed and rounded using the lubridate package. MWE:
library(ggplot2)
library(lubridate)
library(dplyr)
lakers$month <- ymd(lakers$date) %>% round_date(unit = 'month')
items_by_month <- lakers %>% group_by(month) %>% summarize(count = n()) %>%
mutate(count = count / 1000)
ggplot(data = items_by_month, aes(x = month, y = count)) +
geom_line() +
stat_smooth(method = 'lm', data = items_by_month)
model <- lm(data = items_by_month, count ~ month)
summary(model)
time <- max(items_by_month$month) - min(items_by_month$month)
coef(model)['month'] * as.numeric(time)
The plot indicates that ggplot, at least, understands what's going on with the regression model.

But in summary(model) the coefficient on month is on the order of 10^-7, which is about 5 orders of magnitude too small: the plot shows an increase of about 2.5 between the first and last dates, but the last line shows an increase of about 2.5 * 10^-5.
Note that I've divided the count column by 10^3, in order to get values that are easier to read (and closer to my actual use case). But that shouldn't effect either the plot or lm. Also, I know there are more sophisticated techniques than linear regression for analyzing time series data; but I'm just looking at gross trends over time, not factor out seasonal patterns, etc.
lubridatepackage is designed to facilitate working with dates. See the vignette here, and note the x-axis labels in the plot. However, your observation thatmonthsmight be internally stored as seconds led me to look more carefully at the underlying class, which is theRbasePOSIXct, and which does indeed use seconds from 1970-01-01 00:00:00 UTC. So the multiplier on the coefficient did the job. – Dan Hicks Mar 17 '16 at 17:55Rpackages for maximum likelihood regression models utterly fail when dates are regressors (because the software does not internally standardize the values). For dates past the year 2000 or so this can create a particularly toxic error in which most, but not all, precision is lost--and so goes undetected. – whuber Mar 17 '16 at 18:19