Re: [R] howto calculate column means in data frame

From: Berend Hasselman <bhh_at_xs4all.nl>
Date: Sun, 10 Apr 2011 08:48:10 -0700 (PDT)

jamaas wrote:
>
> Long story short, I have a big iterative procedure that produces a long
> list of data.frames such as the one called
> "results" here. Is there an easy way to produce a similar list of
> data.frames comprised of the mean of each of the
> columns in results, such that it ends up like the one I've shown in
> "resultsmean" below?
>
> I've tried apply and lapply, still not got the correct arguments. As
> usual, TIA.
>
> Jim
>

>> results

> [[1]]
> name LOR23 BIA23 MSE23 H0R23
> 1 0.2111122 -1.012228 -0.095937 0.035650 1.00
> 2 0.2111122 -0.836300 0.079991 0.042322 0.75
> 3 0.2111122 -0.518631 0.397659 0.214593 0.50
>
>
> [[2]]
> name LOR23 BIA23 MSE23 H0R23
> 1 0.2211122 -0.724630 0.191660 0.051308 1
> 2 0.2211122 -0.781812 0.134478 0.033872 1
> 3 0.2211122 -0.522109 0.394181 0.164628 0.75
>
>
> would like
>
>> resultsmean

> [[1]]
> name LOR23 BIA23 MSE23 H0R23
> 1 0.2111122 -0.78333 0.12734 0.097160 0.75
>
> [[2]]
> name LOR23 BIA23 MSE23 H0R23
> 1 0.2211122 -0.67566 0.2400 0.08266 0.916
>

lapply(results, FUN=colMeans)

Berend

--
View this message in context: http://r.789695.n4.nabble.com/howto-calculate-column-means-in-data-frame-tp3439932p3439959.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.
Received on Sun 10 Apr 2011 - 15:51:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 10 Apr 2011 - 17:00:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive