[R] how to reverse a list
Seth Falcon
sfalcon at fhcrc.org
Thu Apr 12 01:24:30 CEST 2007
"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
More information about the R-help
mailing list