Match with negation

后端 未结 1 1812
灰色年华
灰色年华 2020-12-31 16:28

This is really simple but I can\'t seem to locate it. I know R has a negated version of %in% that returns \"not in.\" Obviously I could just use !(x %in

相关标签:
1条回答
  • 2020-12-31 17:09

    Just out of interest. Defining

    "%w/o%" <- function(x, y) x[!x %in% y] 
    '%ni%' <- Negate('%in%')
    
    > benchmark(y[y%ni%x], y%w/o%x,replications=1000)
             test replications elapsed relative user.self sys.self user.child
    2   y %w/o% x         1000    5.32 1.000000      4.60     0.70         NA
    1 y[y %ni% x]         1000    5.34 1.003759      4.68     0.65         NA
      sys.child
    2        NA
    1        NA
    

    Do i get a cookie?

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