I want to scan the column 'var2' for elements that appear in an other column 'var1' and, where they match, find the proportion 'value2'/'value1' depending on the levels of the column 'type'. The desired output would be a list or a data frame.
var1<- c(8, 1, 1, 2, 3, 1, 4, 5, 2, 6, 1, 3, 7)
var2 <- c(NA,8,NA,NA,NA,3,NA,NA,5,NA,6,6,NA)
value1 <- c(4340, NA, 3740, 3825, 3845, NA, 4005, 2660, NA, 3055, NA, NA, 5800)
value2 <- c(NA, 30, NA, NA, NA, 5, NA, NA, 15, NA, 1, 20, NA)
type <- c('Fish','Crab','Fish','Fish','Fish','Bird','Fish','Fish','Bird','Fish','Bird','Crab','Fish')
df <- data.frame(var1,var2,value1,value2,type)