Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对R中的每种类型的组执行acf绘图_R_Ggplot2_Time Series - Fatal编程技术网

对R中的每种类型的组执行acf绘图

对R中的每种类型的组执行acf绘图,r,ggplot2,time-series,R,Ggplot2,Time Series,这里是mydata的一小部分 transport<- structure(list(date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L), .Label = c("01.01.2001", "01.02.2001", "01.03.2001", "01.04.2001", "01.05.2001",

这里是mydata的一小部分

transport<- structure(list(date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
11L, 12L), .Label = c("01.01.2001", "01.02.2001", "01.03.2001", 
"01.04.2001", "01.05.2001", "01.06.2001", "01.07.2001", "01.08.2001", 
"01.09.2001", "01.10.2001", "01.11.2001", "01.12.2001"), class = "factor"), 
    Market_82 = c(7000L, 7272L, 7668L, 7869L, 8057L, 8428L, 8587L, 
    8823L, 8922L, 9178L, 9306L, 9439L, 3725L, 4883L, 8186L, 7525L, 
    6335L, 4252L, 5642L, 1326L, 8605L, 3501L, 1944L, 7332L), 
    transport = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
    ), .Label = c("plane", "train"), class = "factor")), .Names = c("date", 
"Market_82", "transport"), class = "data.frame", row.names = c(NA, 
-24L))
组变量-运输

对于每种类型的运输,我必须得到时间序列的acf图

像这样的

如何为每个传输执行acf绘图? 我有很多小组。如何在文件夹中进行绘图 C:/Users/admin/Documents/myplot

我们可以通过预测中的Acf来实现这一点

如果我们也想要这个头衔,那么

lst <- lapply(split(transport['Market_82'], transport$transport), acf, plot = FALSE)
par(mfrow = c(2, 1))
lapply(names(lst), function(x) plot(lst[[x]], main = x))

我们可以通过预测中的Acf实现这一点

如果我们也想要这个头衔,那么

lst <- lapply(split(transport['Market_82'], transport$transport), acf, plot = FALSE)
par(mfrow = c(2, 1))
lapply(names(lst), function(x) plot(lst[[x]], main = x))

阿克伦的答案是正确的。由于您将问题标记为,因此也可以使用forcast包中的ggAcf

第一步是分割数据

transport_split <- split(transport, transport$transport)

阿克伦的回答恰到好处。由于您将问题标记为,因此也可以使用forcast包中的ggAcf

第一步是分割数据

transport_split <- split(transport, transport$transport)