The following code works for me using the data you posted. The only changes I made to my original code were to write Category with an upper case C to match your data and to add the arrange() function at the end to sort the final data frame so that data from each year are displayed together.
library(dplyr)
DF <- structure(list(Category = c("Education", "Education", "Children",
"Misc", "Education", "Misc"),
month = c(10L, 5L, 1L, 8L, 8L, 12L),
replies = c(463L, 72L, 52L, 304L, 46L, 42L),
title = c("NEW WHITE NATIONAL SCHOOL (K-12) FORMING....",
"Homeschool lessons", "Book suggestions for children and young adults",
"Firefox - A Better Browser For Whites That's Spreading Like Wildfire",
"College textbooks: buy/sell",
"Free Online Course on How to Start a Business"),
views = c(210859L, 69853L, 34967L, 166373L, 38115L, 43691L),
year = c(2005L, 2004L, 2012L, 2005L, 2007L, 2004L),
moyr = c(50,33, 125, 48, 72, 40)), row.names = c(NA, 6L), class = "data.frame")
AnnualTotal <- DF %>% group_by(year) %>% summarize(Total = sum(views))
#> `summarise()` ungrouping output (override with `.groups` argument)
Cat_Year <- DF %>% group_by(Category, year) %>%
summarise(GroupTotal = sum(views))
#> `summarise()` regrouping output by 'Category' (override with `.groups` argument)
Cat_Year <- inner_join(Cat_Year, AnnualTotal, by = "year")
Cat_Year
#> # A tibble: 6 x 4
#> # Groups: Category [3]
#> Category year GroupTotal Total
#> <chr> <int> <int> <int>
#> 1 Children 2012 34967 34967
#> 2 Education 2004 69853 113544
#> 3 Education 2005 210859 377232
#> 4 Education 2007 38115 38115
#> 5 Misc 2004 43691 113544
#> 6 Misc 2005 166373 377232
Cat_Year <- Cat_Year %>% mutate(Ratio = GroupTotal/Total) %>%
arrange(year, Category)
Cat_Year
#> # A tibble: 6 x 5
#> # Groups: Category [3]
#> Category year GroupTotal Total Ratio
#> <chr> <int> <int> <int> <dbl>
#> 1 Education 2004 69853 113544 0.615
#> 2 Misc 2004 43691 113544 0.385
#> 3 Education 2005 210859 377232 0.559
#> 4 Misc 2005 166373 377232 0.441
#> 5 Education 2007 38115 38115 1
#> 6 Children 2012 34967 34967 1
Created on 2020-09-11 by the reprex package (v0.3.0)