Hi Vasilis,
Your question has more to do with telepathy than statistics, but I
will attempt an answer anyway. You have in your possession a matrix
(perhaps) named Matrix. Within are at least two columns of something,
one of which contains dates. You have revealed that the other column
contains numeric values. Given these two admissions, I am convinced
that Matrix, despite its name, is a data frame [1].
The question "Is this even correct?" can be answered three times.
No - you have created a vector "vars" and then tried to do something
with "var"
No - you have asked for a sequence of numbers from 1 to the length of
Matrix[,2] with intervals of 22 in the attempt to transform the date
component of each observation into quarterly values. No matter if the
date intervals are days, weeks or quarters, this will not produce the
intervals you want.
No - Your result will be 1/22 as long as the original column of dates
and will contain values that at best express the index order of the
original values.
Now for the good news. As the values in Matrix[,2] are probably dates,
you may be able to calculate a new set of values that will represent
the quarter in which they fell. Assume that your dates are character
strings as below:
# make up two years of daily level dates
datestrings<-paste(rep(2001:2002,each=12),
rep(1:12,2),sample(1:28,24),sep="-")
dates<-as.Date(datestrings,"%Y-%m-%d")
qdates<-factor(paste(format(dates,"%Y"),"Q",
floor(as.numeric(format(dates,"%m"))/4)+1,
sep=""))
Now you have a factor value for each date that indicates the quarter
in which that date fell. My telepathic expertise does not extend to
what you wanted to do next.
Jim
[1] The values in a matrix must all be of the same data type, and
dates as either character strings or factors are not numbers. It is
possible to coerce dates to numbers, but this is unlikely given the
subsequent information.
On Wed, Jun 29, 2016 at 10:27 AM, Vasilis Bardakos via R-help
<r-help at r-project.org> wrote:> Hello,
> I'm a newbie in R and I tried to run a regression, but the data I
imported are quarterly, weekly and daily.In order to simplify my task I set vars
= Matrix[,2] to exclude the Dates and then I tried to short the data quarterly
so I did the following
> k = var[seq(1,"total # of data",22)]
>
> Is this even correct?
> Also, for some reason when I set var = Matrix[,2] somehow the values
changed from rationals to integers.
> Thank you in advance
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.