0

I am relatively new to R and I could not find anything online for what I intend to do with my dataframe. The situation is the following:

I have multiple rows with the same Facility Name. Each facility reports different chemicals with different emissions. So for example, if facility x emits 3 chemicals I would have 3 rows with facility x, where row 1 specificies facility x's output for chemical a, row 2 specificies facility x's output for chemical b, and row 3 specificies facility x's output for chemical c.

Facility y for example emits 2 chemicals so I would have 2 rows with facility y, where row 4 specifies facility y's output for chemical a, and row 5 specifies facility y's output for chemical b.

Now i would like to reorder the dataframe so that I have every facility only once as a row, and for every chemical the facility reports an additional column.

I hope it is clear, and i would be very happy to get help on this issue. kind regards, Franziska

  • 1
    It sounds like you may want to reshape your data from long to wide (see [this](https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format/57013551#57013551) post for examples). If so, I would recommend using `pivot_wider` from `tidyr` package. If you want more detailed help, I would recommend editing your question with example data. This could be made up for illustration, or you can use `dput(head(df))` and copy/paste result (assumes `df` is your data.frame). Also, it would help to show clearly what your final, desired output would look like in the end. – Ben Nov 23 '20 at 19:51
  • thank your for your help Ben. it actually worked with the pivot_wider command ! – franziska Nov 24 '20 at 17:57

0 Answers0