Skip to content
Prev 109532 / 398500 Next

combining lists with same names with 'c'

On 2/15/2007 5:59 AM, Eric Archer wrote:
If you know that your update always has all elements named, you could 
use something like this:

 > my.list <- list(a = 1, c = 2)
 > update <- list(a = "a", b = "b")
 > my.list[names(update)] <- update
 > my.list
$a
[1] "a"

$c
[1] 2

$b
[1] "b"


If some elements of the update are named and some are not, I think 
you'll need several steps:

Check if any are named.  If so, use the method above for the named 
entries.

If any are not named, decide what to do with them, e.g. use c() to put 
them on the end of the result, ignore them, whatever.

Duncan Murdoch