[R] densities from a list with data.frames

Antje niederlein-rstat at yahoo.de
Fri Apr 11 13:57:37 CEST 2008


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...



Richard.Cotton at hsl.gov.uk 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
> 
> 
> ------------------------------------------------------------------------
> ATTENTION:
> 
> This message contains privileged and confidential information intended
> for the addressee(s) only. If this message was sent to you in error,
> you must not disseminate, copy or take any action in reliance on it and
> we request that you notify the sender immediately by return email.
> 
> Opinions expressed in this message and any attachments are not
> necessarily those held by the Health and Safety Laboratory or any person
> connected with the organisation, save those by whom the opinions were
> expressed.
> 
> Please note that any messages sent or received by the Health and Safety
> Laboratory email system may be monitored and stored in an information
> retrieval system.
> ------------------------------------------------------------------------
> 
> ------------------------------------------------------------------------
> This e-mail message has been scanned for Viruses and Content and cleared 
> by NetIQ MailMarshal
> ------------------------------------------------------------------------
>



More information about the R-help mailing list