delete_duplicates_DF | R Documentation |
Delete data frame rows if they contain duplicated values.
delete_duplicates_DF( data, duplicated.var, exact = FALSE, stay = "first", choose.var, choose.stay.val, pattern, mc.cores = 1, verbose = TRUE )
data |
data frame; |
duplicated.var |
variable that contains duplicated values |
exact |
logical; values are to be matched as is |
stay |
character; which row with duplicated values will stay; possible values are |
choose.var, choose.stay.val |
vector of additional variable to choose the preferred row and it's preferred value
(used if |
pattern |
deleted pattern (used if |
mc.cores |
integer; number of processors for parallel computation (not supported on Windows) |
verbose |
logical; show messages |
This function checks if there are repeated values in the data frame (in the duplicated.var
).
If repeated values are found, the first row with duplicated value stays, others are deleted (if stay = "first"
).
If stay = "choose"
the first row with duplicated values and choose.var = choose.stay.val
will stay.
If there are no rows with choose.var = choose.stay.val
, the first row will stay.
If stay = "none"
all rows with values that contain pattern will be removed.
Data frame without rows that contain duplicates in duplicated.var
Elena N. Filatova
data <- data.frame (N = c(1:5, 11:15), name = c(rep( "A",4), "AA", rep( "B",3), "BB", "C"), choose = c(rep(c("yes", "no"), 3), "yes", "yes", "no", "no")) delete_duplicates_DF (data = data, duplicated.var = data$N, exact = TRUE, stay = "first") delete_duplicates_DF (data = data, duplicated.var = data$N, exact = FALSE, stay = "first") delete_duplicates_DF (data = data, duplicated.var = data$name, exact = TRUE, stay = "first") delete_duplicates_DF (data = data, duplicated.var = data$name, exact = TRUE, stay = "choose", choose.var = data$choose, choose.stay.val = "yes") delete_duplicates_DF (data = data, duplicated.var = data$name, exact = FALSE, stay = "first") delete_duplicates_DF (data = data, duplicated.var = data$name, exact = FALSE, stay = "choose", choose.var = data$choose, choose.stay.val = "yes") delete_duplicates_DF (data =data, duplicated.var = data$name, stay = "none", pattern = c("A", "B"), exact = TRUE) delete_duplicates_DF (data =data, duplicated.var = data$name, stay = "none", pattern = c("A", "B"), exact = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.