@@ -52,7 +52,8 @@ match = function(x, from, to, filter_from=NULL, filter_to=NULL, data=parent.fram
5252
5353 # remove identical mappings, then map ambivalent to NA
5454 df = data.frame (from = from , to = to )
55- df = df [! duplicated(df $ from ) | rev(duplicated(rev(df $ from )))] = NA
55+ df = df [! duplicated(df ),]
56+ df [duplicated(df $ from ) | rev(duplicated(rev(df $ from ))),] = NA
5657 df = df [! duplicated(df ),]
5758 from = df $ from
5859 to = df $ to
@@ -104,39 +105,3 @@ match = function(x, from, to, filter_from=NULL, filter_to=NULL, data=parent.fram
104105 else
105106 stats :: setNames(to , x )
106107}
107-
108- # ' duplicated() function with extended functionality
109- # '
110- # ' @param x Object to check for duplicates on
111- # ' @param ... Arguments to be passed to R's `duplicated()`
112- # ' @param all Return all instances of duplicated entries
113- # ' @param random Randomly select with entry is marked as duplicate
114- duplicated = function (x , ... , all = F , random = F ) {
115- if (all && random )
116- stop(" Can not return all and randomly selected duplicates" )
117-
118- if (all )
119- base :: duplicated(x , ... ) | base :: duplicated(x , ... , fromLast = TRUE )
120- else if (random ) { # stat.ethz.ch/pipermail/r-help/2010-June/241244.html
121- if ( is.vector(x ) ) {
122- permutation = sample(length(x ))
123- x.perm = x [permutation ]
124- result.perm = duplicated(x.perm , ... )
125- result = result.perm [order(permutation )]
126- return (result )
127- }
128- else if ( is.matrix(x ) ) {
129- permutation = sample(nrow(x ))
130- x.perm = x [permutation ,]
131- result.perm = duplicated(x.perm , ... )
132- result = result.perm [order(permutation )]
133- return (result )
134- }
135- else {
136- stop(paste(" duplicated.random() only supports vectors" ,
137- " matrices for now." ))
138- }
139- }
140- else
141- base :: duplicated(x , ... )
142- }
0 commit comments