The general sequence here is grouping and then summarizing. In your case, you want to group by weekday and then sum all the earnings for each group. Here is an implementation of that using dplyr.
library(dplyr)
sample_data <- tibble(earnings = sample(seq(1, 10000, by= 1), replace = TRUE, 100), weekday = sample(seq(0, 6, by = 1),replace = TRUE, 100))
sample_data %>%
group_by(weekday) %>%
summarise(total_earnings = sum(earnings))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…