Flat Density Time Series

I want to make a probability distribution for some time series data. My data is in the following format

00:00, 3
01:00, 50
05:00, 13
10:00, 34
17:00, 80
21:00, 100

There are some missing values ​​in the time column that R will have to interpolate. I want a nice smooth curve to highlight busy periods. I tried with ts, densityand plot, but they do not produce what I need. For instance,

data1 <- read.csv(file="c:\\abc\\ts.csv", head=FALSE, sep=",")
data1$V1 <- strptime(data1$V1, format="%H:%M")
plot(data1$V2, density(data1$V1), type="l")

But it gives me crazy lines and a probability distribution.

+3
source share
2 answers

I think that you are definitely after the zoo package , which has several functions for working with NS. See Also na.aggregate, na.approxand na.locf.

+2

, . , .

, "texinp" textConnection(), / . texinp read.zoo CSV . , CSV read.zoo.

library(zoo)
library(chron)

texinp <- "
Time,  Mydata
2011-02-06 00:00, 3
2011-02-06 01:00, 50
2011-02-06 05:00, 13
2011-02-06 10:00, 34
2011-02-06 17:00, 80
2011-02-06 21:00, 100"

myd.zoo <- read.zoo(textConnection(texinp), header=TRUE, FUN = as.chron, sep=",")
myd.zoo

plot(myd.zoo)

" ". , , , 100 21:00 " ". , , - , .

Let me know if I am wrong.

+2
source

Source: https://habr.com/ru/post/1790344/


All Articles