我在.csv excel文件中有2列时间序列,“date”和“widgets”
我使用以下方法将文件导入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 ...
如何将因子事件$ date转换为xts或时间序列格式?
例如当我:
hist(things)
Error in hist.default(things) : 'x' must be numeric
答案 0 :(得分: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)