下面有一段代码。我无法理解“decompose.graph”究竟是如何工作的。在下面的代码中,我想看看“comps”中有什么。但它显示为一些列表结构,我无法理解。
我还可以使用哪个功能来查看“comps”的图形表示(我尝试过绘图,但它不起作用)
gr<-graph(c(1,2,1,3,1,4,2,3,2,4,3,4),directed=FALSE)
cl<-cliques(gr,min=2,max=2)
edges <- c()
for (i in seq_along(cl)) {
for (j in seq_along(cl)) {
if ( length(unique(c(cl[[i]], cl[[j]]))) == 3 ) {
edges <- c(edges, c(i,j))
}
}
}
plot(clq.graph) <- simplify(graph(edges))
V(clq.graph)$name <- seq_len(vcount(clq.graph))
comps <- decompose.graph(clq.graph)
lapply(comps, function(x) {
unique(unlist(cl[ V(x)$name ]))
})
答案 0 :(得分:0)
一般来说,如果要查看R中函数后面的代码,可以在命令中键入函数名称,然后按Enter键。这将为您提供代码的概述。例如:
> decompose
会给你:
function (x, type = c("additive", "multiplicative"), filter = NULL)
{
type <- match.arg(type)
l <- length(x)
f <- frequency(x)
if (f <= 1 || length(na.omit(x)) < 2 * f)
stop("time series has no or less than 2 periods")
if (is.null(filter))
filter <- if (!f%%2)
c(0.5, rep(1, f - 1), 0.5)/f
else rep(1, f)/f
trend <- filter(x, filter)
season <- if (type == "additive")
x - trend
else x/trend
periods <- l%/%f
index <- seq(1L, l, by = f) - 1
figure <- numeric(f)
for (i in 1L:f) figure[i] <- mean(season[index + i], na.rm = TRUE)
figure <- if (type == "additive")
figure - mean(figure)
else figure/mean(figure)
seasonal <- ts(rep(figure, periods + 1)[seq_len(l)], start = start(x),
frequency = f)
structure(list(x = x, seasonal = seasonal, trend = trend,
random = if (type == "additive") x - seasonal - trend else x/seasonal/trend,
figure = figure, type = type), class = "decomposed.ts")
}
<environment: namespace:forecast>
我为decompose.graph尝试了相同的但我似乎没有可用的功能。这不是一个特殊的图书馆吗?我也有一些挑战来执行你的代码,因为函数cliques
似乎不可用;包括你正在使用的图书馆会有所帮助。