One possibility is
aggregate(iris[,-5],list(iris[,5]),mean)
Group.1 Sepal.Length Sepal.Width Petal.Length Petal.Width
1 setosa5.006 3.4281.462 0.246
2 versicolor5.936 2.7704.260 1.326
3 virginica6.588 2.9745
: Re: [R] question about "mean"
apply(iris[, -5], 2, tapply, iris$Species, mean)
On Wed, Jun 9, 2010 at 3:43 PM, SH.Chou wrote:
> Hi there:
> I have a question about generating mean value of a data.frame. Take
> iris data for example, if I have a data.frame looking
apply(iris[, -5], 2, tapply, iris$Species, mean)
On Wed, Jun 9, 2010 at 3:43 PM, SH.Chou wrote:
> Hi there:
> I have a question about generating mean value of a data.frame. Take
> iris data for example, if I have a data.frame looking like the following:
> -
>Sepal.Len
Rolf Turner wrote:
>
> On 9/02/2009, at 4:40 PM, bill.venab...@csiro.au wrote:
>
>> Store your 'matrix' as a data frame.
>
> Surely it's a data frame already, since ``school'' is character or
> factor,
> and ``value'' is (must be?) numeric.
>
> People have this unfortunate predilection
On 9/02/2009, at 4:40 PM, bill.venab...@csiro.au wrote:
Store your 'matrix' as a data frame.
Surely it's a data frame already, since ``school'' is character or
factor,
and ``value'' is (must be?) numeric.
People have this unfortunate predilection to refer to data frames a
Store your 'matrix' as a data frame. Call it 'SchoolVals' say. Then
SchoolMeans <- with(SchoolVals, tapply(value, school, mean))
should do it. If you have missing values you want to ignore:
SchoolMeans <- with(SchoolVals, tapply(value, school, mean, na.rm = TRUE))
Bill Venables
http://www
6 matches
Mail list logo