I want to check if a row in data.frame() is a duplicate of an existing row. As already pointed out here one way might to be to use the duplicate function. However, if I\'m using
If you replaceduplicated
function with match_df
from plyr
, the issue should be resolved.
library(plyr) # for match_df
table <- NULL;
foo <- function(n, d, nh, v){
newEntry <- data.frame(node_i=n, node_j=nh, dst=d, phi=v);
if(length(table != 0)){
if(nrow(plyr::match_df(table, newEntry))){
add(n, nh, d, v);
}else{
print("it is a duplicate!")
}
}else{
add(n, nh, d, v);
}
}
add <- function(n, d, nh, v){
rbind(table, data.frame(node_i=n, node_j=nh, dst=d, phi=v)) ->> table;
}
bar <- function(){
foo(23,42,5,4.0);
print(table);
foo(22,42,5,4.0);
print(table);
foo(23,42,5,4.0);
print(table);
}
> bar()
node_i node_j dst phi
1 23 42 5 4
Matching on: node_i, node_j, dst, phi
[1] "it is a duplicate!"
node_i node_j dst phi
1 23 42 5 4
Matching on: node_i, node_j, dst, phi
[1] "it is a duplicate!"
node_i node_j dst phi
1 23 42 5 4
> table
node_i node_j dst phi
1 23 42 5 4