我仍然是R的新手,我需要hclust函数的完整语法。我不知道如何获得hclust函数中包含的.Fortran函数的完整语法。下面是使用的.Fortran函数,有2:
hcl <- .Fortran(C_hclust, n = n, len = len, method = as.integer(i.meth),
ia = integer(n), ib = integer(n), crit = double(n), members = as.double(members),
nn = integer(n), disnn = double(n), diss = d)
hcass <- .Fortran(C_hcass2, n = n, ia = hcl$ia, ib = hcl$ib,
order = integer(n), iia = integer(n), iib = integer(n))在hclust函数下面,我从R中的运行语法hclust中获得
function (d, method = "complete", members = NULL)
{
METHODS <- c("ward.D", "single", "complete",
"average", "mcquitty", "median", "centroid",
"ward.D2")
if (method == "ward") {
message("The \"ward\" method has been renamed to \"ward.D\"; note new \"ward.D2\"")
method <- "ward.D"
}
i.meth <- pmatch(method, METHODS)
if (is.na(i.meth))
stop("invalid clustering method", paste("",
method))
if (i.meth == -1)
stop("ambiguous clustering method", paste("",
method))
n <- as.integer(attr(d, "Size"))
if (is.null(n))
stop("invalid dissimilarities")
if (is.na(n) || n > 65536L)
stop("size cannot be NA nor exceed 65536")
if (n < 2)
stop("must have n >= 2 objects to cluster")
len <- as.integer(n * (n - 1)/2)
if (length(d) != len)
(if (length(d) < len)
stop
else warning)("dissimilarities of improper length")
if (is.null(members))
members <- rep(1, n)
else if (length(members) != n)
stop("invalid length of members")
storage.mode(d) <- "double"
hcl <- .Fortran(C_hclust, n = n, len = len, method = as.integer(i.meth),
ia = integer(n), ib = integer(n), crit = double(n), members = as.double(members),
nn = integer(n), disnn = double(n), diss = d)
hcass <- .Fortran(C_hcass2, n = n, ia = hcl$ia, ib = hcl$ib,
order = integer(n), iia = integer(n), iib = integer(n))
structure(list(merge = cbind(hcass$iia[1L:(n - 1)], hcass$iib[1L:(n -
1)]), height = hcl$crit[1L:(n - 1)], order = hcass$order,
labels = attr(d, "Labels"), method = METHODS[i.meth],
call = match.call(), dist.method = attr(d, "method")),
class = "hclust")
}如果您知道如何获得.Fortran的完整语法,请让我知道并非常感谢您。
发布于 2022-04-18 09:35:44
.Fortran是一个基本的R函数,用于从包(或用户脚本)中调用用Fortran编写的函数,但这是非常罕见的。在您发布的代码中,它调用C_hclust和C_hcass2引用的函数。这些可能是hclust包中的私有变量。
因为这些变量是私有的,所以可能没有任何关于如何使用它们的文档。您需要获得hclust的源代码,并在src目录中查找包含Fortran源代码的.f文件。
然而,调用私有函数总是一个坏主意。在下一次更新时,包作者可能会在没有通知的情况下更改这些内容,您的代码将停止工作。即使函数没有改变,也可能存在无文档限制,因此您的调用可能无法正常工作。
https://stackoverflow.com/questions/71908673
复制相似问题