Forgive me if I haven't formatted this post properly as it is my first.
I am currently doing some research on wine grapes and I am trying to find a way to make the mutate() function work they way I need it to.
Consider two tables of data, Similarity and Wines.
Wines is the main table which lists all the information about the wines, such as taste characteristics, Region, and more importantly Grapes that are used to make that wine.
Similarity is a table that holds a list of grapes that match some taste profile. The idea behind it is to see if can predict a grape based on the flavours associated with it.
It also has a column n that is a count of how many bottles of that grape varietal share the same taste profile. For example lets say I have 2000 bottles of shiraz in the Wines table but only 300 of those bottles have the same taste profile as the input then the Similarity table may look like
Grapes n
Shiraz/Syrah: 300
but obviously with many more grapes than just Shiraz/Syrah.
What I need to do now is somehow get a count of how many bottles in Wines are Shiraz/Syrah and divide n by that number so as to balance the scores.
This is the line of code I am trying:
Similarity %>% mutate(n = n / nrow(filter(Wines, Grapes == Similarity$Grapes))
Clearly this isn't working the way I intended so I guess my question is how do I get the data from another column into the mutate function?
mutate must be working on each row individually so how do I access the name of the grape that corresponds to the n that mutate is targeting?
Thanks in advance and hopefully I have been concise enough.