update.list | R Documentation |
For a list, 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. For a data frame, replace the rows of a data frame by corresponding rows in 'new' with the same value for 'by'.
## S3 method for class 'list'
update(object, new, unnamed=FALSE, ...)
## S3 method for class 'data.frame'
update(object, new, by, by.x=by, by.y=by,
append=TRUE, verbose=FALSE, ...)
object |
List or data frame to be updated. |
new |
List or data frame containing new elements/rows. |
unnamed |
Logical. If |
by , by.x , by.y |
Character. Name of column to use for matching data frame rows. |
append |
Logical. If |
verbose |
Logical. If |
... |
optional method arguments (ignored). |
update.list |
a list a constructed from the elements of |
update.data.frame |
a data frame constructed from the rows of
|
These methods can be called directly or as via the S3 base method for
update
.
Gregory R. Warnes greg@warnes.net
update
, merge
# Update list
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
# Update data frame
old <- data.frame(letter=letters[1:5], number=1:5)
new <- data.frame(letter=letters[c(5, 1, 7)], number=c(-5, -1, -7))
update(old, new, by="letter") # default is append=TRUE
update(old, new, by="letter", append=FALSE)
update(old, new, by="letter", verbose=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.