[R] rbinding some elements from a list and obtain another list

David Winsemius dwinsemius at comcast.net
Mon Apr 29 17:46:30 CEST 2013


On Apr 29, 2013, at 6:54 AM, De Castro Pascual, Montserrat wrote:

> Hi everybody,
> 
> 
> 
> I have a list, where every element of this list is a data frame.
> 
> 
> 
> An example:
> 
> 
> 
> Mylist<-list(A=data.frame, B=data.frame, C=data.frame, D=data.frame)

I'm looking at this apparently malformed command and wondering if that is the root of all your problems. Do you know how to make a simple successful example of a list of dataframes?

-- 
David.

> I want to rbind some elements of this list.
> 
> As an example:
> 
> 
> 
> Output<-list(AB=data.frame, CD=data.frame)
> 
> 
> 
> Where
> 
> AB=rbind(A,B)
> 
> CD=rbind(C,D)
> 
> 
> 
> 
> 
> I’ve tried:
> 
> 
> 
> f<-function(x){
> 
>  for (i in seq(1,length(names(x)),2)){
> 
>    aa<-do.call(rbind,x[i:i+1])
> 
>    aa
> 
>  }}
> 
> bb<-f(mylist)
> 
> 
> 
> or
> 
> 
> 
> f<-function(x){
> 
>  for (i in seq(1,length(names(x)),2)){
> 
>    aa[i]<-do.call(rbind,x[i:i+1])
> 
>    list(aa[i])
> 
>    }}
> 
> bb<-f (mylist)
> 
> 
> 
> but it doesn’t works!!!!
> 
> 
> 
> f<-function(x){
> 
> +   for (i in seq(1,length(names(x)),2)){
> 
> +     aa<-do.call(rbind,x[i:i+1])
> 
> +     aa
> 
> +   }}
> 
>> bb<-f(mylist)
> 
>> bb
> 
> NULL
> 
>> f<-function(x){
> 
> +   for (i in seq(1,length(names(x)),2)){
> 
> +     aa<-do.call(rbind,x[i:i+1])
> 
> +     aa
> 
> +   }}
> 
>> bb<-f(mylist)
> 
>> 
> 
>> f<-function(x){
> 
> +   for (i in seq(1,length(names(x)),2)){
> 
> +     aa[i]<-do.call(rbind,x[i:i+1])
> 
> +     list(aa[i])
> 
> +   }}
> 
>> bb<-f(mylist)
> 
> Mensajes de aviso perdidos
> 
> 1: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 2: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 3: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 4: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 5: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 6: In aa[i] <- do.call(rbind, x[i:i + 1]) :
> 
>  número de items para para sustituir no es un múltiplo de la longitud del
> reemplazo
> 
> 
> 
> 
> 
> Thanks!
> 
> 
> 
> Montserrat
> 
> 
> 
> 
> 	[[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