[英]Call .Fortran in R for hclust
我仍然是 R 的新手,我需要 hclust function 的完整語法。我不知道如何獲得 hclust function 中包含的 .Fortran function 的完整語法。下面是 8237380 使用的函數是 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 function 以下,我從 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")
}
如果您知道如何獲得完整的語法 fo.Fortran,請告訴我,非常感謝。
.Fortran
是一個基礎 R function 用於從包(或用戶腳本,但這種情況很少見)中調用 Fortran 中編寫的函數。 在您發布的代碼中,它調用C_hclust
和C_hcass2
引用的函數。 這些可能是hclust
package 中的私有變量。
因為這些變量是私有的,所以可能沒有關於如何使用它們的任何文檔。 您需要獲取hclust
的源代碼,並在src
目錄中查找包含 Fortran 源代碼的.f
文件。
但是,調用私有函數總是一個壞主意。 Package 作者可能會在下次更新時更改這些內容,恕不另行通知,您的代碼將停止工作。 即使 function 沒有改變,它也可能存在未記錄的限制,因此您的呼叫可能無法正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.