3 differ2()

The differ2() function codes differences between two vectors as a 1; otherwise, 0. This function is based on Stata’s egen differ() command. 2

x <- 1:5
y <- c(1, 6, 3, 8, 5)

z <- differ2(x, y)

cbind(x, y, z)
##      x y z
## [1,] 1 1 0
## [2,] 2 6 1
## [3,] 3 3 0
## [4,] 4 8 1
## [5,] 5 5 0