[R] apply function over same column of all objects in a list

R. Michael Weylandt michael.weylandt at gmail.com
Thu Aug 2 01:58:09 CEST 2012


I'm a little confused on your data structure -- can you use dput() as
described here [1] to give a small reproducible example?

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

Michael

On Wed, Aug 1, 2012 at 10:38 AM, gail <ortoga-r at yahoo.de> wrote:
> Thank you!!! But I realise I've simplified my data to the point that your
> solution doesn't actually work -- not your fault, mine! My list is actually
> more complicated than what I presented it to be; it's not composed of
> numerical matrices but of lists, each being composed of 7 columns, the first
> two of each (the ones that I am interested in, x and y) being numerical.
> This is what my list really looks like (truncated):
>
>> summary(mylist)
>       Length Class   Mode
> moh6  7      density list
> moh7  7      density list
> moh8  7      density list
> ...
> etc.
>
>> summary(mylist[[3]]) # I've taken number 3 as an example, but they're all
>> the same
>           Length Class  Mode
> x         512    -none- numeric
> y         512    -none- numeric
> bw          1    -none- numeric
> n           1    -none- numeric
> call        2    -none- call
> data.name   1    -none- character
> has.na      1    -none- logical
>
> Any suggestion how to get the max of column y for each sub-list (moh6, moh7,
> moh8 etc.), and to the max of all these individual maxes? By the way,
>
> lapply(list1,FUN=function(x)x[,2][which.max(x[,2])])
>
> gives me the individual maxes (for a list composed of numerical matrices),
> but how do I get to the overall max?

Possibly

max(unlist(list1))

if I understand you correctly.

>
> Many thanks ...
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638681p4638705.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list