I have a data frame (DF) with two columns. In column one I have dates, in column two I have my value of interest (VOI).
DF's display would be this:
|---------------------|------------------|
| Date | VOI |
|---------------------|------------------|
| Jan-1971 | 34 |
|---------------------|------------------|
| Jan-1972 | 28 |
|---------------------|------------------|
| Jan-1973 | 29 |
|---------------------|------------------|
| Jan-1974 | 37 |
|---------------------|------------------|
| ... | ... |
|---------------------|------------------|
| Jan-2017 | 36 |
|---------------------|------------------|
| Fev-1971 | 48 |
|---------------------|------------------|
| Fev-1972 | 49 |
|---------------------|------------------|
| Fev-1973 | 52 |
|---------------------|------------------|
| Fev-1974 | 50 |
|---------------------|------------------|
| ... | ... |
|---------------------|------------------|
| Mar-1971 | 30 |
|---------------------|------------------|
| ... | ... |
|---------------------|------------------|
| Mar-2017 | 36 |
|---------------------|------------------|
| ... | ... |
|---------------------|------------------|
| Dez-1971 | 15 |
|---------------------|------------------|
| ... | ... |
|---------------------|------------------|
| Dez-2017 | 19 |
|---------------------|------------------|
In a nutshell, the data are presented in aggregated cycles of months.
First I have all the VOIs for January from 1971 to 2017 (47 data points), then I have all the VOIs for February of the same period, hence, the same amount of points. This repetition goes on until December, also with 47 data points.
I applied ymd() from the lubridate to transform my date into POSIXct values.
Now I wanted to create a time series object out of my VOIs. I tried:
ts = xts(x = df$Vazao, order.by = index(df$Date))
and
ts = xts(x = df$Vazao, order.by = df$Data)
but none worked. I don't know where I am making a mistake, but I wonder it has anything to do with the fact my dates don't come chronologically. I thought that using the ymd() command would sort that out and "make R understand" that my times series goes from Jan 1971, Feb 1971, Mar 1971, ..., Dec 2017.
How would I transform this data frame into a time series object?
Thank you for your input.