Suppose I have a full pattern file such like:
pattern<-data.frame(x1=c(0,0,0,1,0,1,1,1),
                 x2=c(0,0,1,0,1,1,0,1),
                 x3=c(0,1,0,0,1,0,1,1),
                 y=c(11,14, 12, 14, 16, 18, 19, 20))
pattern
  x1 x2 x3  y
1  0  0  0 11
2  0  0  1 14
3  0  1  0 12
4  1  0  0 14
5  0  1  1 16
6  1  1  0 18
7  1  0  1 19
8  1  1  1 20
And a data file:
set.seed(123)
df<-data.frame(a=rbinom(100, 1, 0.5), 
               b=rbinom(100, 1, 0.2), 
               c=rbinom(100, 1, 0.6))
head(df)
  a b c
1 0 0 1
2 1 0 0
3 0 0 0
4 1 1 1
5 1 0 1
6 0 1 0
What I want is to search each row of df from the pattern and fill in the y's value such like:
  a b c y
1 0 0 1 14
2 1 0 0 14
3 0 0 0 11
4 1 1 1 20
5 1 0 1 19
6 0 1 0 12
I'm wondering Whether there's a easy want to do that in R.
 
     
     
    