Comparing 2 data frames, if value is present replace with 1 or else 0 nrow(df1$v1) = 63849
    nrow(df2$v2) = 3244
ifelse(df1$v2 == df$v1, 1, 0)


I know this is an easy question but I tried different procedures but none of them are useful, 

for(i in 1:nrow(df2)){
for(j in 1:nrow(df1)){
    if(df2$v1[i] == df1$v2[j]){
      df1$v2&lt;- 1
    }
    df1$v2 &lt;- 0
  }
}


This does the job but it take quiet sometime to get the job done.

Other Methods:
Method 1:

df1$v2 &lt;- ifelse(df2$v1 %in% df1$v1, 1,0 )
Error in `$&lt;-.data.frame`(`*tmp*`, v2 , value = c(1, 1, 1, 1, 1, 1,  : 


replacement has 3244 rows, data has 63849

Method 2:

df1$v2 &lt;- ifelse(do.call(paste0, df2$v1) %in% 
do.call(paste0, df1$v1), 1,0 )
summary(df1$v2)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      0       0       0       0       0       0 


Do suggest me if you have any better solution.
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)