Pulling data based on the quater

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Pulling data based on the quater

ka727
This post has NOT been accepted by the mailing list yet.
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.
Reply | Threaded
Open this post in threaded view
|

Re: Pulling data based on the quater

arun kirshna
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.


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Pulling data based on the quater

ka727
This post has NOT been accepted by the mailing list yet.
Thanks a lot for the reply Arun.

I would like to pull the quarter for that particular year. say i want Q2 for year 2014 r Q2 for year 2013.

You assistance is very much appreciated.

Thanks Raghu
Reply | Threaded
Open this post in threaded view
|

Re: Pulling data based on the quater

arun kirshna
In reply to this post by arun kirshna
Hi Raghu,
Using the example you provided. If you want Q3 for year 2011 and 2013.

dat[grep("2011 Q3|2013 Q3", Qtr1),] #change accordingly
#    ID Phase RESEARCH Area      Date   Result
#1  100    IV   S_Care  A&P 7/23/2013 Positive
#5 2005    IV    Speci   TH  8/4/2011     <NA>
#6 2006   III    Speci   BN 7/13/2011 Positive

A.K.



Thanks a lot for the reply Arun.

I would like to pull the quarter for that particular year. say i want Q2 for year 2014 r Q2 for year 2013.

You assistance is very much appreciated.

Thanks Raghu


On Wednesday, June 11, 2014 10:19 AM, arun <[hidden email]> wrote:



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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Pulling data based on the quater

ka727
This post has NOT been accepted by the mailing list yet.
Thanks again Arun.

I need another help from you.

I am trying to filter the data, dataframe(dat) further on Result column as
 
data1=dat[dat$'result'!==NA]

but i am getting the below error:

Error: unexpected '=' in "df3=df1[df1$'result'!==" .

your help on this is again appreciated.