Comparing 2 data frames, if value is present replace with 1 or else 0
Here is a way using dplyr:

require(dplyr)
X = data_frame(A=c(1,2,3,4))
Y = data_frame(B=c(5,4,6,7))

X &lt;- X %&gt;%
  mutate(A = A %in% Y$B,
         A = A*1.0) #converts boolean to numeric


or using base R:

X$A &lt;- 1.0*(X$A %in% Y$B)