I think the question might be simple, please help me with this.
I have a dataset like this:
and I need to reshape it like below:
Thanks in advance.
I think the question might be simple, please help me with this.
I have a dataset like this:
and I need to reshape it like below:
Thanks in advance.
I would suggest creating a column name for each observation (count) based on the values from the Location, City, CustomerId and partner rows. e.g. paste0(Location, City, CustomerId, partner, collapse = '/')
Consequently, use reshape2::melt
to "melt" the dataframe to long format.
Afterwards, use:
tidyr::separate(
data,
"collapsedColName",
into = c("Location", "City", "CustomerId", "partner"),
sep = "/"
)
to recreate those variables.