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

De Castro Pascual, Montserrat mdecastro at creal.cat
Tue Apr 30 08:55:33 CEST 2013


Hi David,

Sorry if I have explain me wrong!
Mylist<-list(A=data.frame, B=data.frame, C=data.frame, D=data.frame)
I know that this is a malformed command, only was a fast way to descrive
mylist.

Thank you!

-----Mensaje original-----
De: David Winsemius [mailto:dwinsemius en comcast.net]
Enviado el: lunes, 29 de abril de 2013 17:47
Para: De Castro Pascual, Montserrat
CC: r-help en r-project.org
Asunto: Re: [R] rbinding some elements from a list and obtain another list


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 en 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