Re: [R] How do you apply a function to each variable in a data frame?

From: Carlos J. Gil Bellosta <>
Date: Mon, 03 Nov 2008 18:13:21 +0100

Data frames are lists themselves.

Something like rbind, lapply(, quantile, probs=c(0.1,0.9)) )

should work.

Carlos J. Gil Bellosta

On Mon, 2008-11-03 at 07:03 -0800, zerfetzen wrote:
> I want to apply a more complicated function than what I use in my example,
> but the idea is the same:
> Suppose you have a data frame named x and you want to a function applied to
> each variable, we'll just use the quantile function for this example. I'm
> trying all sorts of apply functions, but not having luck. My best guess
> would be:
> sapply(x, FUN=quantile) mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 03 Nov 2008 - 17:15:34 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 Mon 03 Nov 2008 - 21:30:20 GMT.

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

list of date sections of archive