I'm trying to create a new var "PERIOD" based on dates. The sample data is given below:
Date
1/10/2012
1/11/2012
1/12/2012
1/13/2012
1/14/2012
1/15/2012
1/16/2012
1/17/2012
1/18/2012
After conditioning the new dataset looks like:
Date PERIOD
1/10/2012 Y1
1/11/2012 Y1
1/12/2012 Y1
1/13/2012 Y1
1/14/2012 Y1
1/15/2012 Y2
1/16/2012 Y2
1/17/2012 Y2
1/18/2012 Y2
The code I was using is
dat$PERIOD<-{If '1/10/2012' <= as.Date(dat$Date) <= '1/14/2012' dat$PERIOD='Y1' else
If '1/15/2012' <= as.Date(dat$Date) <= '1/18/2012'dat$PERIOD='Y2'
}
But I'm getting error:
Error: unexpected string constant in dat$PERIOD<-{If '1/10/2012'
Thank you. Regards,