[R] list syntax question: which subscript is which

Patrick Burns pburns at pburns.seanet.com
Wed Oct 15 10:19:51 CEST 2008


Alternatively if a number of such operations will be
done and memory is not an issue, then you could do:

singlefoo <- do.call('rbind', foo)
max(singlefoo[, 1])

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

jim holtman wrote:
> actually meant to say:
>
> max(sapply(foo, function(x) max(x[,1])))
>
> On Tue, Oct 14, 2008 at 5:49 PM, Carl Witthoft <carl at witthoft.com> wrote:
>   
>> Hi,
>> Sorry to bother with something that should be simple, but I can't find it.
>>
>> Suppose I have a list, each element of which is a 2xN dataframe, where N
>> could be different for each element.
>> Is there some simple structure to let me examine all the elements of each
>> element's first column?  For example:
>>
>>     
>>> foo
>>>       
>> $first
>>     [,1] [,2]
>> [1,]    1    4
>> [2,]    2    5
>> [3,]    3    6
>>
>> $second
>>     [,1] [,2]
>> [1,]    1    6
>> [2,]    2    8
>> [3,]    3    6
>> [4,]    4    8
>>
>> To find the maximum element in all first columns (say, to set the range of a
>> plot where all first columns are x-data), I'd like the legal equivalent of
>>
>>     
>>> max(foo[[*]][,1])
>>>       
>> (where here "*" is a wildcard intended to span all elements of foo)
>>
>> Or do I have to use one of the apply() functions?
>>
>> thanks
>> Carl
>>
>> ______________________________________________
>> 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