So i've created a summarised data frame from a larger df which i want to use to calculate percentages.
tibble::tribble(
~Year, ~Rider_Class, ~yearly_transactions,
2021, "casual", 2528702L,
2021, "member", 3065797L,
2022, "casual", 2321824L,
2022, "member", 3345462L
)
my goal is to get the total of both categories of rider class from each year, then divide that by each rider class to get my percentages, but I'm struggling with how to calculate the sum of transactions based on the conditions in the "year" column.
based on some reading, I attempted this code:
sum (Transactions_per_Year[which(Transactions_per_Year$Year == "2021"),Transactions_per_Year$yearly_transactions]
but my end result was
Error: Incomplete expression: sum (Transactions_per_Year[which(Transactions_per_Year$Year == "2021"),Transactions_per_Year$yearly_transactions]