[R] vector of dates

jim holtman jholtman at gmail.com
Thu Jul 7 15:52:41 CEST 2011

```You are storing the results in to a vector that is converted to
numeric; that is why you see the numbers.  Try this:

>  dataval=as.Date("2011/07/01")
>   date_val=seq(dataval,length=260,by="-7 day")
>   date_inizio=c()
>   date_condizione=c()
>   for (k in 1:length(date_val)){
+       date_inizio[k]=seq(date_val[k],length=2,by="-5 years")[2]
+       date_condizione[k]=seq(date_val[k],length=2,by="-2 years")[2]
+       }
> str(date_inizio)
num [1:260] 13330 13323 13316 13309 13302 ...
> class(date_inizio) <- "Date"
> str(date_inizio)
Date[1:260], format: "2006-07-01" "2006-06-24" "2006-06-17"
"2006-06-10" "2006-06-03" "2006-05-27" ...
>

On Thu, Jul 7, 2011 at 9:35 AM,  <Barbara.Rogo at uniroma1.it> wrote:
>
>   I have to construct a vector of date with a cycle "for". I use the function
>   "seq", but when I allocate in a vector, this becomes a number!!!
>   How do I have? thank you
>   Example:
>   dataval=as.Date("2011/07/01")
>   date_val=seq(dataval,length=260,by="-7 day")
>   date_inizio=c()
>   date_condizione=c()
>   for (k in 1:length(date_val)){
>       date_inizio[k]=seq(date_val[k],length=2,by="-5 years")[2]
>       date_condizione[k]=seq(date_val[k],length=2,by="-2 years")[2]
>       }
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

```