We have "big data frame" and "small data frame". Var1s are my ID, and Var2s are some value.
df1 <- data.frame(row.names=1:10, var1=c("A","B","C","D","E","F","G","H","I","J"), var2=runif(10))
df2 <- data.frame(row.names=1:4, var1=c("B","D","K","A"), var2=runif(4))
I want to compare both data frame and receive new data.frame "DF", which look like: [head(DF)]
var1 var2 Compare
1 A 0.7145085 1
2 B 0.9966129 1
3 C 0.5062709 0
4 D 0.4899432 1
5 E 0.6491614 0
6 F 0.8308064 0
I only want to compare df1$var1 with df2$var2.
The aim of this task is calculating the sum of var2 (from data frame df1), where compare=1.
I think about logical function, but this check only row by row...as you see I will have all "FALSE".