Suppose i had two vectors which i incorporate into a data frame like so:
a <- c("dog", "cat", "dog", "camel", "dog", "cat", "dog")
b <- c(1,0,1,1,1,0,1)
x <- data.frame(a,b)
vector b represents a 0 or 1 value for presence or absence of the corresponding value(animal) in vector a in data frame x.
Using group_by and summarise i found the frequency of occurence/presence of "dog", "cat", and "camel" in vector b. The frequency of camel is 1, of cat is 0, and of dog is 4. Now i wanted to create a new vector c in the data frame x which would have the values 4,0,4, 1,4,0, 4. Vector c contains the total frequency of occurrence/presence of the animals for every corresponding animal name in vector a.
I am giving the relevant code with associated comments in the following reprex, please help if you can.
http://rpubs.com/blue_eyes/523835