I have a df with 6 columns and >5000 rows. I need to group the columns based on information in a second table (samples), and then get the mean values for each group and place into a new dataframe.
Column names will not always be the same or structured as shown below: it is necessary to group based on the values in the second table.
I've searched the forums but I don't know the terminology for what I'm trying to accomplish and have come up empty handed.
Thanks for any help!
>head(df,3)
| | Control_Rep1 | Ethanol_Rep1 | Control_Rep2 | Ethanol_Rep2 | Control_Rep3 | Ethanol_Rep3 |
|--------|--------------|--------------|--------------|--------------|--------------|--------------|
| Q0120 | 22 | 29 | 25 | 39 | 13 | 23 |
| R0010W | 3694 | 6205 | 3322 | 7110 | 4985 | 10513 |
| R0020C | 3024 | 3564 | 2799 | 4191 | 5030 | 6214 |
>samples
| Identifier | Treatment |
|--------------|-----------|
| Control_Rep1 | Control |
| Ethanol_Rep1 | Ethanol |
| Control_Rep2 | Control |
| Ethanol_Rep2 | Ethanol |
| Control_Rep3 | Control |
| Ethanol_Rep3 | Ethanol |
>Desired_Table
| | Control | Ethanol |
|--------|------------|------------|
| Q0120 | 20 | 30.3333333 |
| R0010W | 4000.33333 | 7942.66667 |
| R0020C | 3617.66667 | 4656.33333 |