How to handle “argument 'incomparables != FALSE' is not used (yet)”?

前端 未结 1 1302
轮回少年
轮回少年 2021-01-23 11:29

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

1条回答
  •  猫巷女王i
    2021-01-23 12:17

    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);
    }
    

    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                  
    

    0 讨论(0)
提交回复
热议问题