Hi there, 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)) ) Can anybody help? I'm sure there is a nice short way to do this :-) Antje
Richard.Cotton at hsl.gov.uk
2008-Apr-11 11:38 UTC
[R] densities from a list with data.frames
> I have a list which consists of data frames (all data frames have thesame> 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 inform...{{dropped:20}}