[R] Selecting elements in lists with a row condition

David Winsemius dwinsemius at comcast.net
Tue Feb 4 22:57:18 CET 2014


On Feb 4, 2014, at 11:54 AM, Francesca Pancotto wrote:

> Hello A. k. 
> thanks for the suggestion.
> 
> I tried this but it does not work. I probably use it in the wrong way.
> This is what it tells me, 
> 
> 
> do.call(rbind,lapply(bank.list,function(x) x[x[,"p_made"]==406,]))
> 
> Errore in match.names(clabs, names(xi)) : 
>  names do not match previous names
> 

As teh message says, you are either  working with a set of list which have different names or you are creating data.frames with that problem. What does this show"

sapply(bank.list, names)

If they are all the same, then the output should be very , very regular.

-- 
david.
> What am I doing wrong?
> f.
> 
> ----------------------------------
> Francesca Pancotto
> Università degli Studi di Modena e Reggio Emilia
> Palazzo Dossetti - Viale Allegri, 9 - 42121 Reggio Emilia
> Office: +39 0522 523264
> Web: https://sites.google.com/site/francescapancotto/
> ----------------------------------
> 
> Il giorno 04/feb/2014, alle ore 16:42, arun <smartpink111 at yahoo.com> ha scritto:
> 
>> Hi,
>> Try:
>> 
>> If `lst1` is the list:
>> do.call(rbind,lapply(lst1,function(x) x[x[,"p_made"]==406,]))
>> A.K.
>> 
>> 
>> 
>> 
>> On Tuesday, February 4, 2014 8:53 AM, Francesca <francesca.pancotto at gmail.com> wrote:
>> Dear Contributors
>> sorry but the message was sent involuntary.
>> I am asking some advice on how to solve the following problem.
>> I have a list composed of 78 elements, each of which is a matrix of factors
>> and numbers, similar to the following
>> 
>> bank_name   date px_last_CIB       Q.Y    p_made p_for
>> 1       CIB 10/02/06        1.33 p406-q406    406     406
>> 2       CIB 10/23/06        1.28 p406-q406    406     406
>> 3       CIB 11/22/06        1.28 p406-q406    406     406
>> 4       CIB 10/02/06        1.35 p406-q107    406     107
>> 5       CIB 10/23/06        1.32 p406-q107    406     107
>> 6       CIB 11/22/06        1.32 p406-q107    406     107
>> 
>> 
>> Each of these matrixes changes for the column name bank_name and for the
>> suffix _CIB which reports the name as in bank_name. Moreover each matrix as
>> a different number of rows, so that I cannot transform it into a large
>> matrix.
>> 
>> I need to create a matrix made of the rows of each element of the list that
>> respect the criterium
>> that the column p_made is = to 406.
>> I need to pick each of the elements of each matrix that is contained in the
>> list elements, that satisfy this condition.
>> 
>> It seems difficult to me but perhaps is super easy.
>> Thanks for any help you can provide.
>> 
>> Francesca
>> 
>> 
>> 
>> On 4 February 2014 12:42, Francesca <francesca.pancotto at gmail.com> wrote:
>> 
>>> Dear Contributors
>>> I am asking some advice on how to solve the following problem.
>>> I have a list composed of 78 elements, each of which is a matrix of
>>> factors and numbers, similar to the following
>>> 
>>> bank_name   date px_last_CIB       Q.Y    p_made p_for
>>> 1       CIB 10/02/06        1.33 p406-q406    406     406
>>> 2       CIB 10/23/06        1.28 p406-q406    406     406
>>> 3       CIB 11/22/06        1.28 p406-q406    406     406
>>> 4       CIB 10/02/06        1.35 p406-q107    406     107
>>> 5       CIB 10/23/06        1.32 p406-q107    406     107
>>> 6       CIB 11/22/06        1.32 p406-q107    406     107
>>> 
>>> 
>>> --
>>> 
>>> Francesca
>>> 
>>> ----------------------------------
>>> Francesca Pancotto, PhD
>>> Università di Modena e Reggio Emilia
>>> Viale A. Allegri, 9
>>> 40121 Reggio Emilia
>>> Office: +39 0522 523264
>>> Web: https://sites.google.com/site/francescapancotto/
>> 
>>> ----------------------------------
>>> 
>> 
>> 
>> 
>> -- 
>> 
>> Francesca
>> 
>> ----------------------------------
>> Francesca Pancotto, PhD
>> Università di Modena e Reggio Emilia
>> Viale A. Allegri, 9
>> 40121 Reggio Emilia
>> Office: +39 0522 523264
>> Web: https://sites.google.com/site/francescapancotto/
>> ----------------------------------
>> 
>>    [[alternative HTML version deleted]]
>> 
>> 
>> ______________________________________________
>> 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.
>> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list