Hello! I would like to split a column from a data frame into 2 columns based on the character of each row of that column.
E.g.
Monday 3
Tuesday 5
Tuesday 5
Monday 6
I would like to have 2 columns like this:
Monday Tuesday
3 5
6 5
There are a couple of things that are not clear about your data.
Does the original data have one or two columns?
How can you tell the grouping of the days? Is there another column that marks which Monday goes with which Tuesday or do you simply want Mondays and Tuesdays listed in the order in which they appear?
The key to doing this is that there needs to be a third column that tells R how to group the days and values. In the image you posted, this is information is in the country column. For example, there is only one value of cases for the year 1999 for Angola. The original data you posted has no column that groups the days. If I add one named ID, the pivoting is simple.
Created on 2022-12-05 with reprex v2.0.2
If your real data do not have another column, one can be made but the details of how to do it depend on how the data are organized. What is the rule for grouping a Monday with its corresponding Tuesday?