Message-ID: <40e66e0b0803271324v2bf3a655h8eb6593a263121be@mail.gmail.com>
Date: 2008-03-27T20:24:30Z
From: Douglas Bates
Subject: colMeans in a data.frame with numeric and character data
In-Reply-To: <20080327210535.vheqnkhta00gg844@webmail4.kuleuven.be>
On Thu, Mar 27, 2008 at 3:05 PM, Dimitris Rizopoulos
<Dimitris.Rizopoulos at med.kuleuven.be> wrote:
> try this:
>
> dat <- data.frame(x = rnorm(10), y = rexp(10), z = letters[1:10])
> colMeans(data.matrix(dat[sapply(dat, is.numeric)]))
Alternatively
> sapply(dat, mean)
x y z
-0.5260131 1.0523121 NA
Warning message:
In mean.default(X[[3L]], ...) :
argument is not numeric or logical: returning NA
If you don't like the warning message showing up you can wrap the
expression in suppressWarnings().
> Quoting Diogo Andr? Alagador <dalagador at armail.pt>:
>
> > Hi all,
> >
> > I would like to know if it is posible by, someway, to get colMeans from
> > a data.frame with numeric as well as character data, dispersed all over
> > the object. Note that I would like to get colMeans neglecting character
> > data.
> >
> > I am really in need of some function proceeding in that way?
> >
> > All the best
> >
> > Diogo Andr? Alagador
> >
> > [[alternative HTML version deleted]]
> >
> >
>
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
> ______________________________________________
> R-help at 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.
>