Permalink
Browse files

Allowing "keep_order" to work with "x" or "y"

  • Loading branch information...
1 parent 50a4efb commit 466fa22abf6ca3a8e849de1c1803008a45e9b69f @talgalili committed Feb 11, 2012
Showing with 4 additions and 4 deletions.
  1. +4 −4 merge.data.frame.r
View
@@ -8,7 +8,7 @@ merge.data.frame <- function (x, y, by = intersect(names(x), names(y)), by.x = b
by.y = by, all = FALSE, all.x = all, all.y = all, sort = TRUE,
suffixes = c(".x", ".y"), incomparables = NULL, keep_order, ...)
{
- # if we use the "keep_order" parameter, we might need to modify either the x or y data.frame objects:
+ # if we use the "keep_order" parameter, we might need to modify either the x or y data.frame objects: (either by placing 1 or "x", or by placing 2 or "y")
if(!missing(keep_order))
{
@@ -40,10 +40,10 @@ merge.data.frame <- function (x, y, by = intersect(names(x), names(y)), by.x = b
# x2
# order.by.id...and.remove.it(x2)
- if(keep_order == 1) x<-add.id.column.to.data(x)
- if(keep_order == 2) y<-add.id.column.to.data(y)
+ if(keep_order == 1 | keep_order == "x") x<-add.id.column.to.data(x)
+ if(keep_order == 2 | keep_order == "y") y<-add.id.column.to.data(y)
# if you didn't get 1 or 2 - issue a warning:
- if(!any(keep_order == c(1,2))) warning("The parameter 'keep_order' in the function merge.data.frame only accepts the values 1 (for the x data.frame) or 2 (for the y data.frame)")
+ if(!(any(keep_order == c(1,2)) | any(keep_order == c("x","y"))) ) warning("The parameter 'keep_order' in the function merge.data.frame only accepts the values 1 (for the x data.frame) or 2 (for the y data.frame)")
# sort <- FALSE
# notice that if sort was TRUE, using the keep_order parameter will eventually override it...

0 comments on commit 466fa22

Please sign in to comment.