[R] how to choose dates data?
David Carlson
dcarlson at tamu.edu
Thu Jul 4 16:58:27 CEST 2013
Also
> yrs <- as.Date(c("2007-01-01", "2009-12-31"))
> day[day>=yrs[1] & day<=yrs[2]]
[1] "2008-04-12" "2008-04-12" "2008-04-12"
Should be fast if there are many days to process since it converts
the search criteria, not the data.
-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of arun
Sent: Thursday, July 4, 2013 9:29 AM
To: Gallon Li
Cc: R help
Subject: Re: [R] how to choose dates data?
Hi,
You could try:
day<-as.Date(c("2008-04-12","2011-07-02","2011-09-02","2008-04-12","
2008-04-12"))
indx<-gsub("-.*","",day)
day[indx>="2007" & indx<="2009"]
#[1] "2008-04-12" "2008-04-12" "2008-04-12"
#or
library(xts)
xt1<- xts(seq_along(day),day)
index(xt1["2007/2009"])
#[1] "2008-04-12" "2008-04-12" "2008-04-12"
#or
library(chron)
yr1<-month.day.year(unclass(day))$year
day[yr1>=2007 & yr1<=2009]
#[1] "2008-04-12" "2008-04-12" "2008-04-12"
A.K.
----- Original Message -----
From: Gallon Li <gallon.li at gmail.com>
To: r-help <r-help at stat.math.ethz.ch>
Cc:
Sent: Thursday, July 4, 2013 2:31 AM
Subject: [R] how to choose dates data?
i have converted my data into date format like below:
> day=as.Date(originaldate,"%m/%d/%Y")
> day[1:5]
[1] "2008-04-12" "2011-07-02" "2011-09-02" "2008-04-12" "2008-04-12"
I wish to select only those observations from 2007 to 2009, how can
I
select from this list?
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
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.
______________________________________________
R-help at r-project.org mailing list
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.
More information about the R-help
mailing list