Creating variables that store a range of dates

Looking for a way to store quarterly data into a variable.

Can you provide more information about the structure you need? A list can store almost anything, though if you need only a quarter-identifier and a value, a data.frame would be appropriate.

1 Like

So quarter 1 would be from October 1st - December 31st for example. I want to store it in a variable named Q1 so that once the date goes past that all the information past that date goes to the next quarter or Q2.


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

I am trying to set a period of time as a specific quarter to store all the information that occurs during that time to store in that variable. So for example i would have Quarter1 being dates from 01/01/19 - 03/30/19 and all the information that applies to those dates be able to be stored in it.

Please try to exemplify your request a little better, what kind of information you want to store, what would be the class of the object, a vector, a list, a dataframe?

I agree with FJCC, it seems like a dataframe could be a good option, for example.

data.frame(stringsAsFactors = FALSE,
           quarter = c("Q1", "Q2"),
           from = as.Date(c("2019-01-01", "2019-04-01")),
           to = as.Date(c("2019-03-31", "2019-06-30")),
           var1 = c(1, 2),
           var2 = c("a", "b")
#>   quarter       from         to var1 var2
#> 1      Q1 2019-01-01 2019-03-31    1    a
#> 2      Q2 2019-04-01 2019-06-30    2    b

The Quarter would store values based on simple algebraic equations and store information pulled from various csvs that i mined

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.