Re: [R] Is this sapply behaviour normal?

From: Wacek Kusnierczyk <>
Date: Wed, 25 Jun 2008 23:14:52 +0200

Rolf Turner wrote:
> The answer to your question is ``yeah, sort of''. The reason for the
> difference is that mean() is generic and has a method for data frames,
> according to which the mean of each column of the data frame is found
> in some ``appropriate'' manner. (Essentially the columns of the data
> frame must be either numeric or have some sort of date persuasion, else
> you get a warning and an NA for the column in question. The function
> min()
> is not generic and so if you hit a data frame with min() it (apparently)
> treats that data frame as if it were an atomic vector of data and finds
> the minimum of that atomic vector. Given, of course, that doing so makes
> sense.
> It would seem that you want min() to mimic the behaviour of mean(). To
> achieve this you can, in this instance at least (I think!) simply do
> sapply(dats,function(x){sapply(x,min)})

you can achieve the same with

sapply(dats, sapply, min)

vQ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 25 Jun 2008 - 21:29:05 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 Thu 26 Jun 2008 - 13:31:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive