Skip to content
Back to formatted view

Raw Message

Message-ID: <62AE0CF1D4875C4BBDEC29DB9924ACE87F2177@pnlmse25.pnl.gov>
Date: 2004-01-15T18:50:27Z
From: Waichler, Scott R
Subject: Extracting multiple elements from a list

For a long time I've wanted a way to conveniently extract multiple elements
from a list, which [[ doesn't allow.  Can anyone suggest an efficient
function to do this?  Wouldn't it be a sensible addition to R?

For example,

alist <- list()
alist[[1]] <- list()
alist[[1]]$name <- "first"
alist[[1]]$vec <- 1:4
alist[[2]] <- list()
alist[[2]]$name <- "second"
alist[[2]]$vec <- 5:8
both.vec <- c(alist[[1]]$vec, alist[[2]]$vec)

Can I get both.vec without c() or an explicit loop?

and

new.names <- c("one", "two")
alist[[1]]$name <- new.names[1]
alist[[2]]$name <- new.names[2]

Could I assign the new values in a quasi-vectorized way?

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA   USA