I am trying to create different date ranges based on 4 different start dates as follows:
> length<-c(250,100,30,10)
> dates<-for (i in length){
+ start_date<-Sys.Date()-i
+ print(as.Date(start_date))
+ }
[1] "2023-10-22"
[1] "2024-03-20"
[1] "2024-05-29"
[1] "2024-06-18"
Say the end point is Sys.Date()-1
, which gives me:
> end_point<-Sys.Date()-1
> end_point
[1] "2024-06-27"
However, when I try to store the 4 different start dates into a list for data manipulation, NULL
is returned after I do so:
> x<-(for (i in length){
+ start_date<-Sys.Date()-i
+ print(start_date)
+ })
[1] "2023-10-22"
[1] "2024-03-20"
[1] "2024-05-29"
[1] "2024-06-18"
> x
NULL
May I know, if I would like to save the outpot as a df, how should I go about it? Thanks.