0

I have thousands of rows in this column. I would like to create a different column with four seasons based on Col 1. The 4 seasons are: SON (Sep, Oct, Nov), MAM (Mar, Apr, May), DJF (Dec, Jan, Feb) and JJA (Jun, Jul, Aug) based on the month in Col 1.

Col 1               
6/9/2013 1:15      
3/29/2005 21:00    
4/16/2007 15:15    

So the output would be something like

Col 1             Month    Season  
6/9/2013 1:15     June     JJA
3/29/2005 21:00   March    MAM 
4/16/2007 15:15   April    MAM

Etc.

I did this,

all["month"]<-strptime(all$col1,"%m/%d/%Y %H:%M", tz="UTC")$mon
all["monthname"]<-factor(all$month, levels=1:12, labels=month.name)

But I am not sure how to do this.

maximusyoda
  • 595
  • 3
  • 8
  • 17
  • have you tried the format function to strip the month and then used a series of ifelse statements or cases from the, i think, memisc package? – n8sty Aug 14 '14 at 20:02
  • Note the the answer to the duplicate converted to POSIXlt and your `t1` object is already a POSIXlt-object since that is what strptime returns. – IRTFM Aug 14 '14 at 20:05
  • I have never used postix before. Trying to understand it. I am able to assign months like (1) all["month"]<-strptime(all$col1,"%m/%d/%Y %H:%M", tz="UTC")$mon (2)all["mont"]<-factor(all$month, levels=1:12, labels=month.name) – maximusyoda Aug 14 '14 at 20:06

0 Answers0