[R] Pulling data based on the quater

arun smartpink111 at yahoo.com
Wed Jun 11 16:19:56 CEST 2014


Hi,
Please Check ?as.yearqtr() fromlibrary(zoo) 

dat <- read.table(text="ID  Phase RESEARCH Area   Date Result
100   IV         S_Care A&P 7/23/2013 Positive
1001   IV         P_Care EU 12/20/2012 Positive
2001   IV         Car        AS 9/13/2012 Positive
20003   III         Spec     IN 10/6/2011 NA
2005    IV         Speci   TH 8/4/2011 NA
2006  III         Speci     BN 7/13/2011 Positive
21345  II         Pri     HY 2/3/2011 Positive",sep="",header=TRUE,stringsAsFactors=FALSE) 


library(zoo)
Qtr1 <- as.yearqtr(dat$Date, format="%m/%d/%Y")
dat[grep("Q3",Qtr1),]
#    ID Phase RESEARCH Area      Date   Result
#1  100    IV   S_Care  A&P 7/23/2013 Positive
#3 2001    IV      Car   AS 9/13/2012 Positive
#5 2005    IV    Speci   TH  8/4/2011     <NA>
#6 2006   III    Speci   BN 7/13/2011 Positive
A.K.




Hi ,

I have a dataset as below,

ID  Phase RESEARCH Area   Date Result
100   IV         S_Care A&P 7/23/2013 Positive
1001   IV         P_Care EU 12/20/2012 Positive
2001   IV         Car        AS 9/13/2012 Positive
20003   III         Spec     IN 10/6/2011 NA
2005    IV         Speci   TH 8/4/2011 NA
2006  III         Speci     BN 7/13/2011 Positive
21345  II         Pri     HY 2/3/2011 Positive

I would like to pull data based on the Quarter, for example say if i want data for 3rd quarter based on the date column how do i do it.

I tried the lubridate package but was not able to get the required result.

can any one of you assist me on this.

Your help is very much appreciated. 




More information about the R-help mailing list