Working on my second project for R. I'm trying to create some variable groups using dplyr
, but I'm not sure what the heck I'm doing here.
I'm working with financial data and among the categories, there are several different forms of travel, listed as such:
Travel - Gas, Travel - Airfare, Travel - Subway...
I want to create a new tibble
that groups all the Travel subtypes as one Travel subgroup. Is there a good way to do this?
I've been trying to use the dplyr
filter
function to no effect so far.
Sorry, I was really tired and forgot to put an example up
I have data that's like this:
Month - Year - Category - Amount
01 - 2016 - "Travel- Air" - 247.02
01 - 2016 - "Travel- Car" - 29.04
01 - 2016 - "Retail" - 45.00
03 - 2017 - "Travel - Air" - 253.60
I'm trying to group things so that all the transactions of one type in a particular month/year are summed together like this:
Total_Category_Transactions_Month <- Total_Transactions %>%
group_by(month,Year,Category) %>%
summarize(monthly = sum(Amount))
But after looking at my data, there are just way too many things that are grouped up as "Travel - foo." I'd like to keep that detail for later to analyze, but for the big scale picture, I want to see if I can lump all those Travel expenses as one thing each month.
The Output should end up being:
Month - Year - Category - Amount
01 - 2016 - "Travel" - 276.06
01 - 2016 - "Retail" - 45.00
03 - 2017 - "Travel" - 253.60
Where all the subtypes of category Travel_Foo from the same month and year are added together into one category just called Travel