r - Converting xts to ts: Error in Round(frequency) -
i have imported csv data have turned xts object. if try convert ts object (with end goal of using functions acf) get:
"error in round(frequency) : non-numeric argument mathematical function"
the code convert is:
library("zoo") #working 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"])
the time regular, variation in 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"
some of data has na points:
> 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
update:
changing per second resolution, , non-na subset doesn't help:
> as.ts(web02ts[2:10,1]) error in round(frequency) : non-numeric argument 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 >
also, frequency(web02ts)
returns null
.
a xts/zoo object must regular have non-null frequency.
you don't show how changed per-second resolution if tried via options(digits.secs=0)
, won't work because affects printing. need this:
# example data set.seed(21) web02ts <- xts(rnorm(10), sys.time()+1:10+runif(10)/3) web02ts_reg <- align.time(web02ts,1) frequency(web02ts_reg) # [1] 1 as.ts(web02ts_reg) # time series: # start = 1 # end = 10 # frequency = 1 # [1] 0.793013171 0.522251264 1.746222241 -1.271336123 2.197389533 # [6] 0.433130777 -1.570199630 -0.934905667 0.063493345 -0.002393336
Comments
Post a Comment