How do I transform a column to col name and have each account and its balances in one row?

I have a dataset with 3 columns: accounts, balances and categories. I need to each category a column name and have each account and its balances in one row. The order of the column names will stay the same but the order of the accounts can change. I also thought of using a template with the category columns already created for formatting purposes.

##input
accounts balance category
1 3 1
1 4 2
2 3 1
2 4 2

##output
accounts category_1 category_2
1 1 2
2 1 2

Hi, welcome!

You can use tidyr::spread() function for that.

If you need more specifyc help, please provide a minimal REPRoducible EXample (reprex). A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.