Date format changes while using levels in R

# A tibble: 70 x 2

value Month_considered
dbl> <S3: yearmon>   
24.8  Apr 2017        
47.0  Apr 2017        
35.2  Apr 2017        
19.4  Apr 2017        
30.9  Apr 2017        
6.64  Apr 2017        
10.7  Apr 2017        
11.5  May 2017        
36.3  May 2017        
6.74  May 2017        
# ... with 60 more rows

When I do levels(intrc_flow$Month_considered) or unique(intrc_flow$Month_considered) the output I get is as following:

 [1] Apr-17 May-17 Jun-17 Jul-17 Aug-17 Sep-17 Oct-17 Nov-17 Dec-17 Jan-18 Feb-18
12 Levels: Apr-17 Aug-17 Dec-17 Feb-18 Jan-18 Jul-17 Jun-17 Mar-17 ... Sep-17

How do I get the levels output as Apr 2017 instead of Apr-17.Thank you.

How did you create this object, the column Month_considered ?

It would be easier to help if you can provide a reprex: FAQ: What's a reproducible example (`reprex`) and how do I create one?

Thanks !

1 Like

Got this fixed actually :slight_smile:

unique(as.yearmon(intrc_flow$Month_considered, "%b%y"))unique(as.yearmon(intrc_flow$Month_considered, "%b-%y"))

Great !

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: FAQ: How do I mark a solution?