Re: [R] densities from a list with data.frames

From: Charilaos Skiadas <>
Date: Fri, 11 Apr 2008 08:09:24 -0400

Did you try Richie's suggestion? The x[,1] part will pick out the first column of the data frame. Seems to do exactly what you asked for.

Haris Skiadas
Department of Mathematics and Computer Science Hanover College

On Apr 11, 2008, at 7:57 AM, Antje wrote:

> Of course, I know, but I cannot apply the function "density" to a
> data frame
> (which is the element of the list) but to a vector coming from a
> data frame.
> That's my problem I'd like to solve...
> schrieb:
>>> I have a list which consists of data frames (all data frames have
>>> the
>> same
>>> amount and type of columns but different length).
>>> Now, I'd like to calculate for each data frame in the list the
>>> density function
>>> of the values of the fist column ($V1).
>>> This list could be an example:
>>> l <- list( data.frame(rnorm(100)), data.frame(rnorm(20)), data.
>>> frame(rnorm(200)) )
>> If you want to do the same thing to every element of a list,
>> lapply (or
>> sapply) is your friend.
>> Try:
>> lapply(l, function(x) density(x[,1]))
>> Regards,
>> Richie.
>> Mathematical Sciences Unit
>> HSL
>> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 11 Apr 2008 - 12:15:32 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 11 Apr 2008 - 15:00:28 GMT.

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

list of date sections of archive