Selecting a data range using months and date over a period of years?

Viewed 29

I am beginner in R. I have a data.frame in which frequencies in one column and dates in other column. I would like to extract counts for two halves of a month, i.e., 1st to 15th and 16th to 31st. The data below is for August Month from 1992 - 2001. I would like to have total counts for two halves (Aug 1 - Aug 15 & Aug 16 - Aug 31). I searched various options in this portal, but could not figure out a way to do it. Please help!!!!

df 1994-08-06 1 1994-08-06 1 1994-08-07 1 1994-08-14 1 1994-08-20 1 1994-08-23 1 1994-08-24 1 1995-08-11 1 1995-08-12 1 1995-08-14 2 1995-08-14 1 1995-08-21 1 1995-08-29 1 1995-08-30 1 1996-08-11 1 1998-08-03 1 1998-08-03 1 1998-08-26 1 1999-08-09 1 2000-08-06 1 2001-08-22 1 2001-08-24 1 2001-08-27 1 2001-08-28 1 2001-08-29 1

The code i used is

df1<-subset(df, format.Date(Dates, "%m/%d")=="08-01" & 
                             format.Date(Dates, "%m/%d")=="08-15")
1 Answers

I found the way to do it. I installed packages "tidyverse" and 'lubridate'.

df1<-c(day(df$Dates))
 length (df1[df1<=15]) 
 length (df1[df1>15])

Thanks!!!

Related