[R] puzzling Date math result
Denis Chabot
chabot.denis at gmail.com
Tue Apr 17 16:44:40 CEST 2012
Hi,
I cannot make a reproducible example easily for my problem, so I'll
describe it as best as I can.
I merged 2 dataframes but was surprised when one line on the x
dataframe did not get a match in the y dataframe, because I knew such
a match existed. There was only one "by" variable in the merge, in
Date format:
in x:
$ période : Date, format: "2009-06-09" "2009-07-09" ...
in y:
$ date : Date, format: "2009-05-12" "2009-06-09" …
I extracted the date that did not match into variables a (from x) and
b (from y):
> a=test1$période[21]
> b=test2$date[22]
> a
[1] "2011-04-06"
> b
[1] "2011-04-06"
and then this very puzzling situation:
a==b
[1] FALSE
> as.integer(a)
[1] 15070
> as.integer(b)
[1] 15070
> as.integer(a)==as.integer(b)
[1] TRUE
Thanks in advance for an explanation or a suggestion to further study
this puzzle,
Denis
sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] fr_CA.UTF-8/en_US.UTF-8/fr_CA.UTF-8/C/fr_CA.UTF-8/fr_CA.UTF-8
attached base packages:
[1] splines stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] doBy_4.5.2 MASS_7.3-17 snow_0.3-8 lme4_0.999375-42
[5] Matrix_1.0-6 lattice_0.20-6 multcomp_1.2-12 mvtnorm_0.9-9992
[9] R2HTML_2.2 survival_2.36-12 gdata_2.8.2
loaded via a namespace (and not attached):
[1] grid_2.15.0 gtools_2.6.2 nlme_3.1-103 stats4_2.15.0 tools_2.15.0
More information about the R-help
mailing list