factor year into 4 quarters


#1

This post was flagged by the community and is temporarily hidden.


#2
> data_comp
# A tibble: 1,317,783 x 9
   index               BidOpen BidHigh BidLow BidClose AskOpen AskHigh AskLow AskClose
   <dttm>                <dbl>   <dbl>  <dbl>    <dbl>   <dbl>   <dbl>  <dbl>    <dbl>
 1 2015-01-05 00:00:00    120.    121.   120.     121.    121.    121.   121.     121.
 2 2015-01-05 00:01:00    120.    121.   120.     121.    121.    121.   121.     121.
 3 2015-01-05 00:02:00    121.    121.   120.     121.    121.    121.   121.     121.
 4 2015-01-05 00:03:00    121.    121.   121.     121.    121.    121.   121.     121.
 5 2015-01-05 00:04:00    121.    121.   120.     121.    121.    121.   121.     121.
 6 2015-01-05 00:05:00    121.    121.   120.     121.    121.    121.   121.     121.
 7 2015-01-05 00:06:00    120.    121.   120.     121.    121.    121.   120.     121.
 8 2015-01-05 00:07:00    120.    121.   120.     121.    121.    121.   120.     121.
 9 2015-01-05 00:08:00    121.    121.   121.     121.    121.    121.   121.     121.
10 2015-01-05 00:09:00    121.    121.   121.     121.    121.    121.   121.     121.
# ... with 1,317,773 more rows
> data_comp %>% mutate(month = months(index), quarter = quarters(index))
# A tibble: 1,317,783 x 11
   index               BidOpen BidHigh BidLow BidClose AskOpen AskHigh AskLow AskClose month quarter
   <dttm>                <dbl>   <dbl>  <dbl>    <dbl>   <dbl>   <dbl>  <dbl>    <dbl> <chr> <chr>  
 1 2015-01-05 00:00:00    120.    121.   120.     121.    121.    121.   121.     121. 1月   Q1     
 2 2015-01-05 00:01:00    120.    121.   120.     121.    121.    121.   121.     121. 1月   Q1     
 3 2015-01-05 00:02:00    121.    121.   120.     121.    121.    121.   121.     121. 1月   Q1     
 4 2015-01-05 00:03:00    121.    121.   121.     121.    121.    121.   121.     121. 1月   Q1     
 5 2015-01-05 00:04:00    121.    121.   120.     121.    121.    121.   121.     121. 1月   Q1     
 6 2015-01-05 00:05:00    121.    121.   120.     121.    121.    121.   121.     121. 1月   Q1     
 7 2015-01-05 00:06:00    120.    121.   120.     121.    121.    121.   120.     121. 1月   Q1     
 8 2015-01-05 00:07:00    120.    121.   120.     121.    121.    121.   120.     121. 1月   Q1     
 9 2015-01-05 00:08:00    121.    121.   121.     121.    121.    121.   121.     121. 1月   Q1     
10 2015-01-05 00:09:00    121.    121.   121.     121.    121.    121.   121.     121. 1月   Q1     
# ... with 1,317,773 more rows

data.table::month and data.table::quarter will be more efficient for high volume dataset.


#3

Huh, I had no idea base R had those functions, TIL.