I have an excel sheet that has turned into a large data dump and I need to organize the data. I was hoping to do this in R since I can edit the code to organize multiple items. In essence, I have the data extracted as shown below with each city in its own cell.
1 NYC Chicago Detroit LA Miami
2 Chicago Sacramento Seattle LA NYC
3 Detroit Miami Sacramento NYC Chicago
I need to extract it so that the numbers at the beginning of the row will be organized with the city. It should look like this:
NYC 1 2 3
Chicago 1 2 3
Detroit 1 3
LA 1 2
Miami 1 3
Sacramento 2 3
Seattle 2
What is the easiest way to do this? I was trying to do an "If, Then" statement, but that does not seem to be working and provides an error.
EDIT: This is a snipit of what the current data looks like. There are 107 rows and 12 columns for reference:
I am currently using the code
library(readxl);df1 <- read_excel('C:\Users\Brittney\Desktop\Data_V1.xlsx') tidyr::separate_rows(df1, September)