Skip to content
Back to formatted view

Raw Message

Message-ID: <4A1A5A9F.1000707@idi.ntnu.no>
Date: 2009-05-25T08:45:19Z
From: Wacek Kusnierczyk
Subject: Creating a list by just using start and final component
In-Reply-To: <4A190E6C.1040209@dbmail.com>

Romain Francois wrote:
> Hollix wrote:
>> Hi there,
>>
>> say, I have 100 matrices (m1,m2,...,m100) which I want to combine in
>> a list.
>> The list, thus, shall contain the matrices as components.
>>
>> Is it necessary to mention all 100 matrices in the list() command? I
>> would
>> like to use just the first and last matrix or something similar.
>>
>> Best,
>> Holger
>>   
> Hi,
>
> you can do something like that:
>
> matrices <- ls( pattern = "m[0-9]+" )
> res <- lapply( matrices, get )

if you expect the items to be in an order like m1, m2, ..., m10, ...,
m100 etc. rather than m1, m10, m100, ..., m2, ..., you'd rather

    res <- lapply(matrices[order(nchar(matrices))], get)

vQ