0

I have a csv file which I read in R

library(xts)
mydata <- read.csv("abc.csv") ==> it becomes a dataframe

Months      Round Premium
December     2    1000
December     1    2000
November     2    1500
November     1    1200
...
January      2    1600
January      1    1200

The months column becomes a character. I would like to make it as xts object for the months column to be index, and the rest of the other columns to be matrix. This is because I wish to plot as time series model.

I have difficulties in making the months column as index.

Anyone can help ?

==> when

phiver
  • 23,048
  • 14
  • 44
  • 56
james lim
  • 39
  • 4

1 Answers1

0

The Months variable has to be in a proper date format (not a character).

You can create it by using for example:
lubridate::parse_date_time(x = mydata$Months, orders = "m")

(but there are many other options).

Then xts for the time-series:
xts(x = mydata[, 2:3], order.by = mydata$Months)

i94pxoe
  • 577
  • 3
  • 11