简体   繁体   中英

how to generate time series data in R

I want to generate time series data logged every 50 ms in a csv file using R for 48 hours.

I tried the following, without success

x<-Sys.time()
x
# [1] "2015-12-05 08:00:29 EST"
x.ts <- ts(x, start=1, freq=2)
x.ts
# Time Series:
# Start = c(1, 1) 
# End = c(10, 1) 
# Frequency = 2 
# [1] 1449317249 1449317249 1449317249 1449317249 1449317249 1449317249
# [7] 1449317249 1449317249 1449317249 1449317249 1449317249 1449317249
# [13] 1449317249 1449317249 1449317249 1449317249 1449317249 1449317249
# [19] 1449317249

Any help is appreciated.

You could try this:

start <- as.POSIXct("2015-12-05 08:00:29.000", "%Y-%m-%d %H:%M:%OS")
end   <- as.POSIXct("2015-12-07 08:00:29.000", "%Y-%m-%d %H:%M:%OS")

x <- seq(start, end, by=0.05)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM