我有一些导入的 csv 数据已变成 xts 对象。如果我尝试将其转换为 ts 对象(最终目标是使用 acf 之类的函数),我会得到:
“回合误差(频率):数学函数的非数字参数”
转换它的代码是:
library("zoo")
#Working With Milliseconds
op <- options(digits.secs=3)
#Rename Function
clean_perfmon = function(x, servername) {
names(x)[names(x)=="X.PDH.CSV.4.0...Coordinated.Universal.Time..0."] <- "Time"
x$Time = strptime(x$Time, "%m/%d/%Y %H:%M:%OS")
return(x)
}
web02 = read.csv("/home/kbrandt/Desktop/Shared/web02_2011_07_20_1.csv")
web02 = clean_perfmon(web02, "NY.WEB02")
web02ts = xts(web02[,-1], web02[,"Time"])
时间大多是规律的,但 MS 有一些变化:
time(web02ts)[1:3]
[1] "2011-07-20 11:21:50.459 EDT" "2011-07-20 11:21:51.457 EDT" "2011-07-20 11:21:52.456 EDT"
一些数据有 NA 点:
> web02ts[1:3,1]
X..NY.WEB02.Process.Idle....Processor.Time
2011-07-20 11:21:50.459 NA
2011-07-20 11:21:51.457 1134.819
2011-07-20 11:21:52.456 1374.877
更新:
更改为每秒分辨率,非 na 子集无济于事:
> as.ts(web02ts[2:10,1])
Error in round(frequency) : Non-numeric argument to mathematical function
> web02ts[2:10,1]
X..NY.WEB02.Process.Idle....Processor.Time
2011-07-20 11:21:51 1134.819
2011-07-20 11:21:52 1374.877
2011-07-20 11:21:53 1060.842
2011-07-20 11:21:54 1067.092
2011-07-20 11:21:55 1195.205
2011-07-20 11:21:56 1223.328
2011-07-20 11:21:57 1121.774
2011-07-20 11:21:58 1187.393
2011-07-20 11:21:59 1378.001
>
此外,frequency(web02ts)
返回NULL
.