update_data {biblio} | R Documentation |
Update data frames
Description
This function compares two versions of the same data frame and detect changes as additions, deleted entries or updates (modified entries).
A method to compare lib_df objects is also provided as well as a replace method.
Usage
update_data(object, revision, key, ...)
## S4 method for signature 'data.frame,data.frame,character'
update_data(
object,
revision,
key,
add = FALSE,
delete = FALSE,
update = FALSE,
...
)
## S4 method for signature 'lib_df,lib_df,missing'
update_data(object, revision, key, ...)
update_data(object, key, ...) <- value
## S4 replacement method for signature 'data.frame,character,data.frame'
update_data(object, key, ...) <- value
## S4 replacement method for signature 'lib_df,missing,lib_df'
update_data(object, key, ...) <- value
Arguments
object |
A data frame or a lib_df object representing the original version. |
revision |
The updated version of 'object' to be compared. |
key |
A character value indicating the column used as identifier. This variable have to be in both versions otherwise this function will retrieve an error. |
... |
Further arguments passed among methods. |
delete , add , update |
Logical value indicating whether the action
should be carried out. If all are |
value |
The updated version of 'object' in the replace methods. |
Value
Either an invisible output with a print in the console or an updated object of class lib_df.
Examples
# Adding an ID to data set iris
iris2 <- iris
iris2$id <- 1:nrow(iris2)
# rows to add using mean values per species
iris_mod <- aggregate(cbind(
Sepal.Length, Sepal.Width, Petal.Length,
Petal.Width
) ~ Species, data = iris2, FUN = mean)
iris_mod$id <- (1:nrow(iris_mod)) + nrow(iris2)
iris_mod <- do.call(rbind, list(iris2, iris_mod[, colnames(iris2)]))
# delete some entries
iris_mod <- iris_mod[-c(15, 75, 105, 145), ]
# modify entries
iris_mod$Petal.Length[c(20, 30)] <- 0
iris_mod$Petal.Width[c(20, 50)] <- 0
# just a comparison
update_data(iris2, iris_mod, key = "id")
# do update
iris2 <- update_data(iris2, iris_mod,
key = "id", delete = TRUE, add = TRUE,
update = TRUE
)