0

我在 .csv excel 文件中有 2 列时间序列,“日期”和“小部件”

我使用以下命令将文件导入 R:

widgets<-read.csv("C:things.csv")
str(things)

'data.frame':   280 obs. of  2 variables:
 $ date: Factor w/ 280 levels "2012-09-12","2012-09-13",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ widgets  : int  5 10 15 20 30 35 40 50 55 60 65 70 75 80 85 90 95 100 ...

如何将因素 things$date 转换为 xts 或时间序列格式?

例如当我:

hist(things)
Error in hist.default(things) : 'x' must be numeric
4

1 回答 1

0

尝试将其作为动物园对象读入,然后转换:

Lines <- "date,widgets
2012-09-12,5
2012-09-13,10
"
library(zoo)
# replace first argument with:  file="C:things.csv"
z <- read.zoo(text = Lines, header = TRUE, sep = ",")
x <- as.xts(z)
于 2013-10-28T20:22:32.743 回答