[R] the way to look at all the codings of any functions

ebi keisyu at gmail.com
Mon Jun 18 06:37:37 CEST 2007


Dear SIr,


In case of looking at the codes of the fuction, "cov",

we find all the codings below.  But, incase of "mean", we don't find
the contents.

Please show me the way to look at all the codings of any functions.

Best regards,
Kei
-----------------------

> cov
function (x, y = NULL, use = "all.obs", method = c("pearson",
    "kendall", "spearman"))
{
    na.method <- pmatch(use, c("all.obs", "complete.obs",
"pairwise.complete.obs"))
    method <- match.arg(method)
    if (is.data.frame(y))
        y <- as.matrix(y)
    else stopifnot(is.atomic(y))
    if (is.data.frame(x))
        x <- as.matrix(x)
    else {
        stopifnot(is.atomic(x))
        if (!is.matrix(x)) {
            if (is.null(y))
                stop("supply both 'x' and 'y' or a matrix-like 'x'")
            x <- as.vector(x)
        }
    }
    if (method == "pearson")
        .Internal(cov(x, y, na.method, method == "kendall"))
    else if (na.method != 3) {
        Rank <- function(u) if (is.matrix(u))
            apply(u, 2, rank, na.last = "keep")
        else rank(u, na.last = "keep")
        if (na.method == 2) {
            ok <- complete.cases(x, y)
            x <- if (is.matrix(x))
                x[ok, ]
            else x[ok]
            if (!is.null(y))
                y <- if (is.matrix(y))
                  y[ok, ]
                else y[ok]
        }
        x <- Rank(x)
        if (!is.null(y))
            y <- Rank(y)
        .Internal(cov(x, y, na.method, method == "kendall"))
    }
    else stop("cannot handle 'pairwise.complete.obs'")
}
<environment: namespace:stats>
>
> mean
function (x, ...)
UseMethod("mean")
<environment: namespace:base>



More information about the R-help mailing list