I am a beginner in R and want to know how it will works for each row.
Eg.
I have a two data frames.
I want to see if the rows exist in the other multiple columns of other data frame.
I want to loop every row in ab$Fruits and check if each name is somewhere in another dataframe bc[E1:E3]columns.
ab<-data.frame(Fruits = c("Apple","Banana"),Units = c("3","2"))
bc<-data.frame("E1"=c("Apple","Grapes","Watermelon","Na"),
"E2"=c("Grapes","Berries","Custard","Guava"),
"E3"=c("Apple","Banana","Grapes","Na"))
eg.
I want to do with loops or any function.When the loops starts, first row of ab$fruits match with each rows of bc,if first row (Apple) match with apple in bc$E1 ,in ab$new column the result should return 1 and loop breaks.Again 2nd row (Banana) search for each column in bc,if it is not match with any row in column bc$E1 ,in ab$new column result should return 0.[I want to do this only to make sum of ab$units == 5]Till it makes sum=5 loop should iterates.
When 3rd time ab$fruits(apple) loop reach from row 1 (Apple) and match with column bc$E3 also row 2 (Banana) matches with Banana the result should be ab$new = 1 for both the rows.
IF ab$new for both the rows ==1 and sum of both the units is >=5 ,create new column in ab$view = "Bill"
output ab:
SN Fruits Number New** view
1 Apple 3 1 Bill
2 Banana 2 1 Bill
I have tried %in% but not happening.
Need advice.