How to handle "arguments" incomparable! = FALSE 'not used (yet) "?
I want to check if a row in data.frame () is a duplicate of an existing row. As already pointed out here , one way would be to use a duplicate function. However, if I use the function, I get the following error:
Error: argument 'incomparables != FALSE' is not used (yet)
In a fairly old post, someone noticed that this is actually a bug in R (more info on here ). My data.frame () looks like this:
data.frame(val1=int,val2=int,val3=int,val4=float);
I am wondering what is actually the problem as there is no "NA" value in my data.frame as
?duplicate
indicates. This may be a very stupid question, but I'm completely new to R and would love any advice on this issue!
Thanks in advance Michael
PS: I have given the example suggested
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(!duplicated(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);
}
However, this doesn't seem to be a problem with duplicate () at all. I get the same error if I try to add another sigh of the line.
If you replace the function duplicated
with match_df
from plyr
, the problem 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);
}
Output
> 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
source to share