R/fix_duplicates.R

Defines functions duplicated2

Documented in duplicated2

#'
#'  This program is free software but it is provided WITHOUT WARRANTY
#'  and with ABSOLUTELY NO GUARANTEE of fitness or functionality for any purpose;
#'  you can redistribute it and/or modify it under the terms of the GNU
#'  General Public License as published by the Free Software Foundation;
#'  either version 2 of the License, or (at your option) any later version.
#'
#'
#'

duplicated2=function(x,type=c("all","first","last"),value=F,invert=F){

  if(type[1]=="all") index = duplicated(x) | duplicated(x, fromLast=TRUE)
  if(type[1]=="first") index = duplicated(x)
  if(type[1]=="last") index = duplicated(x, fromLast=TRUE)

  if(invert) index = !index

  if(value) return(x[index])
  if(!value) return(index)

}
dup2=duplicated2

# duplicated2(c(1:15,2:7),value=F)
# dup2(c(1:15,2:7),value=F)
#
# duplicated2(c(1:15,2:7),value=T)
# dup2(c(1:15,2:7),value=T)
jstrunk001/RSForInvt documentation built on April 18, 2022, 11:03 p.m.