'y' has a default value of NULL, so its value is NULL. Check ?cov to see what happens when it is NULL.
On 10/24/07, Ista Zahn <[EMAIL PROTECTED]> wrote: > Hi all, > I apologize for the ignorance implicit in this question, but I'm > having a hard time figuring out how R functions work. For example, if > I wanted to write a function to compute a variance, I would do > something like > > >my.var <- function(x) (sum(((x-mean(x)))^2))/(length(((x-mean(x))) > ^2)-1) > > And this seems to work, e.g., > > > my.var(V1) > [1] 116.1 > > var(V1) > [1] 116.1 > > But when I try to see what the built-in var function does I get > > > var > function (x, y = NULL, na.rm = FALSE, use) > { > if (missing(use)) > use <- if (na.rm) > "complete.obs" > else "all.obs" > na.method <- pmatch(use, c("all.obs", "complete.obs", > "pairwise.complete.obs")) > if (is.data.frame(x)) > x <- as.matrix(x) > else stopifnot(is.atomic(x)) > if (is.data.frame(y)) > y <- as.matrix(y) > else stopifnot(is.atomic(y)) > .Internal(cov(x, y, na.method, FALSE)) > } > <environment: namespace:stats> > > Being a novice, I can't understand what this means. I only have one > variable, yet the code seems to be based on the covariance between x > and y. What is y? Sorry for such a stupid question. I am just trying > to figure out how R does things, and I can't seem to get my head > around it. Thank you for your patience. > > -Ista Zahn > http://izahn.homedns.org > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.