Re-arrange data frame with concatenating names?


I'm new at trying to re-arrange dataframes in this particular way. Searching the community for splitting up a column keeps returning results for 'separate' , which isn't what I want to do. Essentially my dataframe looks like the left side of the image below, and I need to transform it to the right side. How should I go about this?


This explains how:

Thanks for the reply! I've been toying around with this in every way I can think of but I can't correctly produce the result I'm going for without errors. Sometimes I get exactly what seems like the goal result, but I notice weird aberrations that aren't present normally (like randomly introducing commas within only certain cells).

If I do something like pivot_wider(df, names_from=Sample, values_from=Response) then I get a result similar to what I'm going for, but then I get the weird stuff in some areas too. Also I see this :

Warning message:
Values are not uniquely identified; output will contain list-cols.
* Use `values_fn = list` to suppress this warning.
* Use `values_fn = length` to identify where the duplicates arise
* Use `values_fn = {summary_fun}` to summarise duplicates

Additionally, columns are transformed into class "unknown".
Can you help me with an example of how to use pivot_wider to achieve this goal?

Thanks again

Without your data it's impossible to say what's causing your issues, but the warning message tells you there are duplicate entries.

For any further help you'll have to post your data via dput() or datapasta if your data is in a spreadsheet:

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