How about
> difftime(LAI_simulation$Date, LAI_simulation$Date[1],
units="days")
Time differences in days
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13
-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ahmed Attia
Sent: Wednesday, July 5, 2017 1:24 PM
To: r-help <r-help at r-project.org>
Subject: [R] Convert date to continuous variable in R
How can I convert date to continuous variable staring from 1. I tried
as.numeric but R starts counting from default January 1, 1970 while my data
start Oct 7, 2009.
I need to do this conversion to plot the date on two x-axes (1 and 3).
Ex;
Date LAI
10/7/2009 0
10/8/2009 0.004173
10/9/2009 0.009997
10/10/2009 0.009998
10/11/2009 0.009999
10/12/2009 0.009999
10/13/2009 0.009999
10/14/2009 0.009999
10/15/2009 0.009998
10/16/2009 0.009998
10/17/2009 0.009998
10/18/2009 0.009998
10/19/2009 0.009998
10/20/2009 0.009998
LAI_simulation$Date <- as.Date( LAI_simulation$Date, '%Y/%m/%d')
plot(LAI~Date, data=LAI_simulation)
LAI_simulation$Date<-
as.numeric(LAI_simulation$Date,origin="2009-10-07")
#R does not see the origin
axis.Date(side=3,at=LAI_simulation$Date)
Ahmed Attia, Ph.D.
Agronomist & Soil Scientist
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.