On 9/30/2005 5:57 PM, Lisa Wang wrote:> Hello, > > Could you please let me know how to see the "mean" function in R . The > following is what I see when type in "mean" and "enter" > > mean > function (x, ...) > UseMethod("mean") > <environment: namespace:base> > > I would like to see how the function is writen.The "UseMethod" part tells you that mean is a generic function. There are lots of different implementations, depending on what sort of thing x is. You can see the default one using "mean.default": > mean.default function (x, trim = 0, na.rm = FALSE, ...) { if (!is.numeric(x) && !is.complex(x) && !is.logical(x)) { warning("argument is not numeric or logical: returning NA") return(as.numeric(NA)) } if (na.rm) x <- x[!is.na(x)] trim <- trim[1] n <- length(x) if (trim > 0 && n > 0) { if (is.complex(x)) stop("trimmed means are not defined for complex data") if (trim >= 0.5) return(median(x, na.rm = FALSE)) lo <- floor(n * trim) + 1 hi <- n + 1 - lo x <- sort(x, partial = unique(c(lo, hi)))[lo:hi] n <- hi - lo + 1 } if (is.integer(x)) sum(as.numeric(x))/n else sum(x)/n } <environment: namespace:base> Duncan Murdoch
Try base::mean.default S??ren ________________________________ Fra: r-help-bounces at stat.math.ethz.ch p?? vegne af Lisa Wang Sendt: fr 30-09-2005 23:57 Til: R-Help Emne: [R] 'mean' function Hello, Could you please let me know how to see the "mean" function in R . The following is what I see when type in "mean" and "enter" mean function (x, ...) UseMethod("mean") <environment: namespace:base> I would like to see how the function is writen. Thanks a lot Lisa Wang Toronto, Ca
Hello, Could you please let me know how to see the "mean" function in R . The following is what I see when type in "mean" and "enter" mean function (x, ...) UseMethod("mean") <environment: namespace:base> I would like to see how the function is writen. Thanks a lot Lisa Wang Toronto, Ca -------------- next part -------------- This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient. Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited. If you have received this e-mail in error, please contact the sender and delete all copies. Opinions, conclusions or other information contained in this e-mail may not be that of the organization.
Type "?mean" and hit "enter" in the console to see the description of the function. # randomly draw 5 numbers between 1 and 10 without replacement randomlist = sample(1:10, 5) # calculate the mean of the list meanoflist = mean(randomlist) # show the result meanoflist HTH, Martin --- Lisa Wang <lisawang at uhnres.utoronto.ca> wrote:> Hello, > > Could you please let me know how to see the "mean" > function in R . The > following is what I see when type in "mean" and > "enter" > > mean > function (x, ...) > UseMethod("mean") > <environment: namespace:base> > > I would like to see how the function is writen. > > Thanks a lot > > Lisa Wang > Toronto, Ca > > > This e-mail may contain confidential and/or > privileged information for the sole use of the > intended recipient. Any review or distribution by > anyone other than the person for whom it was > originally intended is strictly prohibited. If you > have received this e-mail in error, please contact > the sender and delete all copies. Opinions, > conclusions or other information contained in this > e-mail may not be that of the organization.>______________________________________________> R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html