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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.