Update the elements of a list

Function to update the elements of a list to contain all of the named elements of a new list, overwriting elements with the same name, and (optionally) copying unnamed elements.

Keywords
manip, data
Usage


# S3 method for list
update(object,
       new,
       unnamed=FALSE,
       ...)








Arguments
object

Object to be updated.

new

List or dataframe containing new elements.

unnamed

Logical. If TRUE, unnamed elements of new will be appended to object.

...

optional method arguments (ignored)

Value

A new list constructed from the elements of object by merging the elements of old and new with named items of new replacing the corresponding elements of old. Unnamed elements of new will be appened unless unnamed=FALSE.

Note

This method can be called directly, or as via the S3 base method for update.

See Also

update, merge

Aliases
  • update.list
Examples
old <- list(a=1,b="red",c=1.37)
new <- list(b="green",c=2.4)

update(old, new)
update.list(old,new)  # equivalent

older <- list(a=0, b="orange", 4, 5, 6)
newer <- list(b="purple", 7, 8, 9)
update(older, newer)               # ignores unnamed elements of newer
update(older, newer, unnamed=TRUE) # appends unnamed elements of newer

<!-- %%data(iris) -->
<!-- %%iris$Species <- as.character(iris$Species) -->
<!-- %%df.old <- cbind(iris[1:5,], letters=1:5) -->
<!-- %%df.new <- df.old[3:5,] -->
<!-- %%df.new$Petal.Width <- df.new$Petal.Width + 0.1 -->
<!-- %% -->
<!-- %%df.old -->
<!-- %%df.new -->
<!-- %%update(df.old, df.new, by=c(letters)) -->
Documentation reproduced from package gdata, version 2.18.0, License: GPL-2

Community examples

Looks like there are no examples yet.