I have a data frame that looks like this:
query page clicks
apples /apples 50
oranges /oranges 25
apples /bad-apples 40
bananas /bananas 25
apples /all-fruits 10
I need this, where a new column, querySum, is created that sums up all of the clicks for a particular query. So, in the example above, the row for apples should always show 100 (50+40+10).
query page clicks querySum
apples /apples 50 100
oranges /oranges 25 25
apples /bad-apples 40 100
bananas /bananas 25 25
apples /all-fruits 10 100
I tried dplyr, but it created a smaller table with just unique values. Is there a way to apply this to every row in a new column, perhaps using a loop?
df$querySum <- df %>% group_by(query) %>% summarise(querySum = sum(clicks))