[R] how to reverse a list

Weiwei Shi helprhelp at gmail.com
Thu Apr 12 17:52:08 CEST 2007


Thanks all of you!

But my next question is, how to improve R programming skills? I never
have time in improving it but I feel I need to.

Regards,

W

On 4/11/07, Seth Falcon <sfalcon at fhcrc.org> wrote:
> "Weiwei Shi" <helprhelp at gmail.com> writes:
>
> > I forgot to add my bad solution here:
> >
> > reverseList <- function(xlist){
> >   blist <- xlist[!is.na(xlist)]
> >   x0 <- unlist(blist)
> >   l0 <- length(blist)
> >   d0 <- as.data.frame(matrix(0, l0, 3))
> >   d0[,1] <- names(x0)
> >   d0[,2] <- x0
> >
>
> There is a helper function in Biobase that does this:
>
> reverseSplit
>
>          > reverseSplit
>          function (inList)
>          {
>              lens = sapply(inList, length)
>              nms = rep(names(inList), lens)
>              vals = unlist(inList)
>              split(nms, vals)
>          }
>          <environment: namespace:Biobase>
>
> + seth
>
> --
> Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
> http://bioconductor.org
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III



More information about the R-help mailing list