Re: [R] error in using by + median

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 02 May 2008 15:10:40 +0100 (BST)

The help says

      A data frame is split by row into data frames subsetted by the
      values of one or more factors, and function 'FUN' is applied to
      each subset in turn.

You attempting to apply median() to a data frame -- it does no work, unlike mean()

On Fri, 2 May 2008, vito muggeo wrote:

> dear all,
> Could anyone explain me the behaviour of median() within by()?
> (I am running R.2.7.0)
>
> thanks,
> vito
>
>> H<-cbind(rep(0:1,l=20),matrix(rnorm(20*2),20,2))
>> by(H[,-1],H[,1],mean)
> INDICES: 0
> V1 V2
> -0.2101069 0.2954377
> ---------------------------------------------------------------------------------------------------------------------
> INDICES: 1
> V1 V2
> -0.23682173 -0.01225147
>> by(H[,-1],H[,1],median)
> Error in median.default(data[x, , drop = FALSE], ...) : need numeric data
>>
>
>
> --
> ====================================
> Vito M.R. Muggeo
> Dip.to Sc Statist e Matem `Vianelli'
> UniversitÓ di Palermo
> viale delle Scienze, edificio 13
> 90128 Palermo - ITALY
> tel: 091 6626240
> fax: 091 485726/485612
> http://dssm.unipa.it/vmuggeo
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


______________________________________________ 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 Fri 02 May 2008 - 14:17:09 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 Fri 02 May 2008 - 15:00:34 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