dataframe "Bangladesh" looked like-
Province Country Cases Date
1 NA Bangladesh 0 2020-01-22
2 NA Bangladesh 1 2020-01-23
3 NA Bangladesh 2 2020-01-24
4 NA Bangladesh 3 2020-01-25
To convert to xts i used the following code
Bangladesh_xts <- xts( Bangladesh, order.by= Bangladesh$Date)
Bangladesh_Final <- Bangladesh_xts[,-4]
Province Country Cases
2020-01-22 NA Bangladesh 0
2020-01-23 NA Bangladesh 1
2020-01-24 NA Bangladesh 2
2020-01-25 NA Bangladesh 3
is.xts (Bangladesh_Final) shows "TRUE". But when I am trying
plot(Bangladesh_Final$Cases)
This message is shown every time "Error in plot.xts(Bangladesh_Final$Cases) : 'x' must be a time-series object". What am i doing wrong?
We need to select the Cases to avoid changing the class from numeric to character as xts is also a matrix and matrix can have only a single class
Bangladesh_xts <- xts( Bangladesh$Cases, order.by= as.Date(Bangladesh$Date))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With